날짜로 년도에 맞게 월별 카운트 하려고합니다
년도별 카운트는 나오지만 ,, 이미지처럼 group by가 되지 않습니다.
열심히도전중입니다. 도움부탁드려요
select
datepart(mm,regdate)as 월
,case when a.year = '2018' then count(*) end "2018년"
,case when a.year = '2019' then count(*) end "2019년"
,case when a.year = '2020' then count(*) end "2020년"
from table a
where
a.year in ('2018','2019','2020')
group by a.year,datepart(mm, regdate)
order by datepart(mm, regdate)
Comment 1
-
건우아빠
2020.05.21 21:53
datepart(mm,regdate)as 월
,sum(case when a.year = '2018' then 1 end) "2018년"
,sum(case when a.year = '2019' then 1 end) "2019년"
,sum(case when a.year = '2020' then 1 end) "2020년"
from table a
where
a.year in ('2018','2019','2020')
group by a.year,datepart(mm, regdate)
order by datepart(mm, regdate)