May I ask how to count the broken door in below table? I want to show the record of Block B also, but I only can show Block A record.
Also, if my selection table query is too long, but I will reuse many times. How can I define the valuable to the long selection query?
Table: doorStatus
| Door | Block | key_Number | Broken |
|---|---|---|---|
| door1 | A | 001 | Y |
| door2 | A | 001 | Y |
| door3 | A | 002 | Y |
| door4 | B | 013 | N |
Except result:
| Block | key_number | Count_Broken |
|---|---|---|
| A | 001 | 2 |
| A | 002 | 1 |
| B | 013 | 0 |
Thank you for your help.