I have this simple query:
SELECT YEAR(P.DateCreated) ,MONTH(P.DateCreated) ,COUNT(*) AS cnt FROM tbl1, tbl2.... GROUP BY MONTH(P.DateCreated) ,YEAR(P.DateCreated)
this will emit:
now I need the same query, but with the group only in a year:
So:
SELECT YEAR(P.DateCreated) ,COUNT(*) AS cnt FROM tbl1, tbl2.... GROUP BY YEAR(P.DateCreated)
I do not want to make 2 requests.
is there any way i can do with conditional group by
here?
I can do with replacing the other, but I can not replace one with two ...
GROUP BY CASE WHEN @timeMode='y' THEN YEAR(P.DateCreated) WHEN @timeMode='m' THEN MONTH(P.DateCreated), YEAR(P.DateCreated) end
any help?
source share