首先,使用下面语句:
select date, count(date) cnt from user where date is not null group by date
结果:
date cnt
1月 2
2月 2
3月 1
在上面语句基础上改进,使之与要求结果一致:
select max(case when date = '1月' then cnt else 0 end ) 1月,
max(case when date = '2月' then cnt else 0 end ) 2月,
max(case when date = '3月' then cnt else 0 end ) 3月
from (select date, count(date) cnt from user where date is not null group by date)
select date,count(date) from user where date is not null group by date;
select date,coun(date) from user where date is not null group by date