--------------------------
| id | date | type |
--------------------------
| 1 | 2015-04-10 | a |
| 2 | 2015-04-11 | b |
| 3 | 2015-04-13 | c |
| 4 | 2015-04-09 | a |
| 5 | 2015-04-10 | a |
이런 식의 정보가 들어있는 테이블이 있고,
select count(*) from food
where date = '2015-04-10' and type = 'a'
group by date, type
select count(*) from food
where date = '2015-04-10' and type = 'b'
group by date, type
select count(*) from food
where date = '2015-04-10' and type = 'c'
group by date, type
이 세 개의 쿼리를 한 번에 해결하고 싶어요. (왠지 그게 더 좋아보이기도 하고요)
select count(m1.type) as 'a',
count(m2.type) as 'b',
count(m3.tpye) as 'c'
from food as t
inner join food as m1 on m1.id = t.id
inner join food as m2 on m2.id = t.id
inner join food as m3 on m3.id = t.id
where t.date = '2015-04-10'
group by t.date, t.type;
검색해보고 대충 이렇게까지는 만들었는데, 제대로 만들어졌다면 row가 1개 혹은 0개가 나와야하는데, 이렇게하니까 3개가 나오네요 ;;;
어디가 잘못 된걸까요?
그냥 쿼리 3개를 날릴까요?