Table1
ID | First | Last | Branch
111 Amy A 10
222 Yuki B 11
333 Smith C 10
444 David D 12
555 Mike E 13
Table2
Branch | Food | State
10 Burger MI
11 Taco CA
99 Taco CA
13 Taco CA
12 Burger MI
Table3
Food | State | Rating
Burger MI bad
Taco CA bad
Steak TX good
QUESTION: How to make the table below:
Rating | CountState | CountID
Bad 2 5
Good 1 0
I am a novice to SQL, so I tried my best to deliver my thoughts into this question. I am thinking of UNION ALL of two queries but failed. Any idea is appreciated. Thank you very much.
SELECT a.Rating, COUNT(a.Rating) AS CountState
FROM Table1 a
GROUP BY a.Rating
ORDER BY a.Rating