-- 表a
-- 字段 a_status, a_date
-- 数据 0 2013-01-01
-- 数据 1 2013-01-02
-- 数据 0 2013-02-01
-- 数据 1 2013-02-02
-- 数据 1 2013-02-03
-- 求sql:按年和月分组,找出a_status为0的数据条数和a_status为1的数据条数,
-- 要求查出的数据如下:
-- count0 count1 a_date
-- 1 1 2013-01
-- 1 2 2013-02下sql只能查出总的,未区分a_status,可参考。
select count(*) ,a_date
from a
group by year(a_date),
month(a_date);先谢谢了。SQL行业数据select
-- 字段 a_status, a_date
-- 数据 0 2013-01-01
-- 数据 1 2013-01-02
-- 数据 0 2013-02-01
-- 数据 1 2013-02-02
-- 数据 1 2013-02-03
-- 求sql:按年和月分组,找出a_status为0的数据条数和a_status为1的数据条数,
-- 要求查出的数据如下:
-- count0 count1 a_date
-- 1 1 2013-01
-- 1 2 2013-02下sql只能查出总的,未区分a_status,可参考。
select count(*) ,a_date
from a
group by year(a_date),
month(a_date);先谢谢了。SQL行业数据select
select substring(a_date,1,7)
,count(case when a_status=0 then 1 end)
,count(case when a_status=1 then 1 end)
from tb
group by substring(a_date,1,7)
谢谢啦。大哥的sql炉火纯青呀,小弟拜倒。等下忙完了就结贴。