以知表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

解决方案 »

  1.   

    用group by  和 count(*)应该就能完成还有 where来判断yes 和 no
    具体的我也想不出来 应该有很多种自己多想想吧
      

  2.   

    select date_ "日期"
         , 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是标准,其它数据库应该也可以,试试吧,不行再告诉我用的数据库是什么
      

  3.   

    select count(date_)
    where A.status='yes'
    group by date_unionselect count(date_)
    where A.status='no'
    group by date_
    我也不会,瞎写的,不要笑话,我是菜鸟!!!
      

  4.   


    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_;
      

  5.   


    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`;
      

  6.   

    标准sql是怎样的?case when是标准,sum也是
      

  7.   

    select date as 日期
         , sum(decode(status, 'yes', 1, 0)) as 是
         , sum(decode(status, 'no', 1, 0)) as 否
    from A
    group by date
      

  8.   


    case when 不是标准吧
      

  9.   

    case when不行就試試decode的吧,跟java的switch語句差不多
      

  10.   

    MYSQL写法:SELECT date_ 日期,SUM(IF(status='yes',1,0)) 是,SUM(IF(status='no',1,0)) 否 
    FROM a 
    GROUP BY date_ ;
      

  11.   

    select date_ as "日期",count(status) as "是",null as "否" from a where status='yes' group by date_
    union
    select date_ as "日期",null as "是",count(status) as "否" from a where status='no' group by date_;
      

  12.   

    CASE WHEN 是标准,IF和decode不是。
      

  13.   

    顶2楼,在mysql中那儿写也可以的!~