1:虚拟表结构
   
   id        要求完工时间       完成状态
   1         2012-05-04             1
   2         2012-05-04             1
   3         2012-05-03             0
   4         2012-05-03             1
   5         2012-05-04             0
   6         2012-05-03             02:需求
  按 要求完工时间 查出 当前完工时间每个完成状态的count
  table结构   完工时间       完成状态(0)       完成状态(1)
   2012-05-04          1条                2条
   2012-05-03          2条                1条在线等待  求大神赐教

解决方案 »

  1.   

    select finish_time 完工时间,sum(decode(status,0,1,0)) 完成状态(0),sum(decode(status,1,1,0)) 完成状态(1) from tab group by finish_time;
      

  2.   

    WITH t AS (
    SELECT   1 ID, '2012-05-04' ttime, 1 num FROM dual UNION ALL
    SELECT     2, '2012-05-04', 1 FROM dual UNION ALL
    SELECT     3, '2012-05-03', 0 FROM dual UNION ALL
    SELECT     4, '2012-05-03', 1 FROM dual UNION ALL
    SELECT     5, '2012-05-04', 0 FROM dual UNION ALL
    SELECT     6, '2012-05-03', 0 FROM dual )
    SELECT ttime,sum(decode(num,0,1)) sta1, sum(decode(num,1,1)) sta2 FROM t GROUP BY ttime;
      

  3.   

    select date,finishStatus0,finishStatus1 from
    (select date,sum(finishStatus) as finishStatus1 from tb where finishStatus=1 group by date)tb1
    left join
    (select date,sum(finishStatus) finishStatus0 from tb where finishStatus=0 group by date)tb0
    on tb1.date=tb2.date
      

  4.   

    弄的这么壮观  貌似这是比较基本的sql呢
      

  5.   


    create table TestTbl as 
    select 1 as id,'2012-05-04' as sDate,1 as status from dual
    union select 2,'2012-05-04',1 from dual
    union select 3,'2012-05-03',0 from dual
    union select 4,'2012-05-03',1 from dual
    union select 5,'2012-05-04',0 from dual
    union select 6,'2012-05-03',0 from dual;
     
    select sDate ,
    sum(case when status = 0 then 1 else 0 end) as status0,  
    sum(case when status = 1 then 1 else 0 end) as status1  
    from TestTbl 
    group by sDate
      

  6.   

       谢谢大家了   解决了  的decode
      

  7.   

    huan_lxyd    mylovemoon2010  两兄弟  对不住了  分给错地方了  。。