oracle表定义如下:
0 2011-4-2
0 2011-4-4
0 2011-4-8
0 2011-4-10
0 2011-4-15
1 2011-4-15
0 2011-4-17
0 2011-4-18
0 2011-4-20
1 2011-4-20
0 2011-4-28
我想要查询这个月里面那几天没有数据并返回没有数据的记录数和没有数据的最大天数
预期结果是:
没有数据的天数 没有数据的最大天数
21 2011-4-30请各位高手帮下小弟!
0 2011-4-2
0 2011-4-4
0 2011-4-8
0 2011-4-10
0 2011-4-15
1 2011-4-15
0 2011-4-17
0 2011-4-18
0 2011-4-20
1 2011-4-20
0 2011-4-28
我想要查询这个月里面那几天没有数据并返回没有数据的记录数和没有数据的最大天数
预期结果是:
没有数据的天数 没有数据的最大天数
21 2011-4-30请各位高手帮下小弟!
--计算没有num的天数:
SQL> with t as(
2 select 0 num,to_date('2011-4-2','yyyy-mm-dd') dt from dual union all
3 select 0,to_date('2011-4-4','yyyy-mm-dd') from dual union all
4 select 0,to_date('2011-4-8','yyyy-mm-dd') from dual union all
5 select 0,to_date('2011-4-10','yyyy-mm-dd') from dual union all
6 select 0,to_date('2011-4-15','yyyy-mm-dd') from dual union all
7 select 1,to_date('2011-4-15','yyyy-mm-dd') from dual union all
8 select 0,to_date('2011-4-17','yyyy-mm-dd') from dual union all
9 select 0,to_date('2011-4-18','yyyy-mm-dd') from dual union all
10 select 0,to_date('2011-4-20','yyyy-mm-dd') from dual union all
11 select 1,to_date('2011-4-20','yyyy-mm-dd') from dual union all
12 select 0,to_date('2011-4-28','yyyy-mm-dd') from dual)
13 select sum(count(case num when 0 then 1 end)) cnt
14 from t
15 group by dt; CNT
----------
9
再从这个结果中找出最大日期的总日期就行了。
那问题是tab_test3这个表没有啊!你知道我意思么?分不是问题,我问题还没有解决阿!
你一楼说的这个呀
oracle表定义如下:
0 2011-4-2
0 2011-4-4
0 2011-4-8
0 2011-4-10
0 2011-4-15
1 2011-4-15
0 2011-4-17
0 2011-4-18
0 2011-4-20
1 2011-4-20
0 2011-4-28