以知表A
date_ status
2009-09-19 yes
2009-09-19 yes
2009-09-19 yes
2009-09-19 no
2009-09-19 no
2009-09-20 yes
2009-09-20 no
2009-09-20 no
怎样查询得到表B
日期 是 否
2009-09-19 3 2
2009-09-20 1 2
date_ status
2009-09-19 yes
2009-09-19 yes
2009-09-19 yes
2009-09-19 no
2009-09-19 no
2009-09-20 yes
2009-09-20 no
2009-09-20 no
怎样查询得到表B
日期 是 否
2009-09-19 3 2
2009-09-20 1 2
具体的我也想不出来 应该有很多种自己多想想吧
, sum(case when status = 'yes' then 1 else 0 end) "是"
, sum(case when status = 'no' then 1 else 0 end) "否"
from A
group by date_;oralce语法,不过鉴于case when是标准,其它数据库应该也可以,试试吧,不行再告诉我用的数据库是什么
where A.status='yes'
group by date_unionselect count(date_)
where A.status='no'
group by date_
我也不会,瞎写的,不要笑话,我是菜鸟!!!
select date_,count(status),null from a where status='yes' group by date_
union
select date_,null,count(status) from a where status='no' group by date_;
select
test.`date` as "日期",
sum(case when test.`yesOrNo`='yes' then 1 else 0 end) as "是" ,
sum(case when yesOrNo='no' then 1 else 0 end) as "否"
from test
group by test.`date`;
, sum(decode(status, 'yes', 1, 0)) as 是
, sum(decode(status, 'no', 1, 0)) as 否
from A
group by date
case when 不是标准吧
FROM a
GROUP BY date_ ;
union
select date_ as "日期",null as "是",count(status) as "否" from a where status='no' group by date_;