数据表 table日期date    类型type
2007-1-1   0
2007-1-2   0
2007-1-5   1
我想返回两列,一列为type为0的纪录数,第二列为type为1的日期(就只要能满足上述举例),也就是:天数   日期
2     2007-1-5谢谢了!

解决方案 »

  1.   

    select 
    (select count(*) from table where 类型=0) 天数,(select d1 from table where 类型=1) 日期 from dual;
      

  2.   

    更正一下
    select 
    (select count(*) from table where 类型=0) 天数,(select 日期 from table where 类型=1) 日期 from dual;
      

  3.   

    樓主沒表達清楚,
    第二列为type为1的日期----type為1的要是多個取最大日期?select sum(case 类型type when '0' then 1 else 0 end) 天数,
    max(case 类型type when '1' then 日期date else '' end) 日期
    from
    (
    select '2007-1-1' 日期date ,'0' 类型type from dual union all
    select '2007-1-2' ,'0' from dual union all
    select '2007-1-5' ,'1' from dual 
    ) t
    ------------------------------------------
        天数 日期
    1 2 2007-1-5
      

  4.   

    楼上基本OK。
    不过建议使用“DECODE”代替“CASE”,性能好,代码也简洁。