答案 0 :(得分:0)
Date函数是特定于数据库的。下面给出了这个想法,并且可以在大多数数据库中使用:
select month(date) as mon, year(date) as yr, which,
sum(case when day(date) = 1 then 1 else 0 end) as day_01,
sum(case when day(date) = 2 then 1 else 0 end) as day_02,
. . .
sum(case when day(date) = 31 then 1 else 0 end) as day_31
from ((select date, 'reccount' as which, 1 as val from t
) union all
(select date, 'approved' as which, approved as val from t
) union all
(select date, 'signed' as which, signed as val from t
)
) t
group by month(date), year(date), which
order by min(date), which ;