当前位置: 代码迷 >> Oracle技术 >> sql好手们,是你们发挥的时候了
  详细解决方案

sql好手们,是你们发挥的时候了

热度:424   发布时间:2016-04-24 08:05:31.0
sql高手们,是你们发挥的时候了
大家看看下面的列表,按日期进行升序排序时,正常情况下,n_num 下的值应该是逐渐变大才是正确,我如何通过一个sql就可以查询出了不符合要去的需要的数据。(过滤出不符合规律的数据),只有20分了,大家帮帮忙吧

 c_id                            d_date                              n_num 
  01                         2008-03-17                               0
  02                         2008-03-18                               1
  03                         2008-03-19                               2
  04                         2008-03-20                               3
  05                         2008-03-21                               4
  06                         2008-03-22                               3
  07                         2008-03-23                              5
  08                         2008-03-24                               4
  09                         2008-03-25                               10
  10                         2008-03-26                               8
  11                         2008-03-27                               9
  12                         2008-03-28                               10
  13                         2008-03-29                               11
  14                         2008-03-30                               6
------解决思路----------------------
试试这句:
with table1 as (
select '01' c_id, '2008-03-17' d_date, 0 n_num from dual union all
select '02' c_id, '2008-03-18' d_date, 1 n_num from dual union all
select '03' c_id, '2008-03-19' d_date, 2 n_num from dual union all
select '04' c_id, '2008-03-20' d_date, 3 n_num from dual union all
select '05' c_id, '2008-03-21' d_date, 4 n_num from dual union all
select '06' c_id, '2008-03-22' d_date, 3 n_num from dual union all
select '07' c_id, '2008-03-23' d_date, 5 n_num from dual union all
select '08' c_id, '2008-03-24' d_date, 4 n_num from dual union all
select '09' c_id, '2008-03-25' d_date, 10 n_num from dual union all
select '10' c_id, '2008-03-26' d_date, 8 n_num from dual union all
select '11' c_id, '2008-03-27' d_date, 9 n_num from dual union all
select '12' c_id, '2008-03-28' d_date, 10 n_num from dual union all
select '13' c_id, '2008-03-29' d_date, 11 n_num from dual union all
select '14' c_id, '2008-03-30' d_date, 6 n_num from dual
)
select * from table1 a where n_num<(select max(n_num) n_num from table1 b where b.c_id<a.c_id)
  相关解决方案