如果有一个表结构,
fphm,kshm
2014,00000001
2014,00000002
2014,00000003
2014,00000004
2014,00000005
2014,00000007
2014,00000008
2014,00000009
2013,00000120
2013,00000121
2013,00000122
2013,00000124
2013,00000125
(第二个字段内可能是连续的数据,可能存在断点。)
怎样能查询出来这样的结果,查询出连续的记录来。
就像下面的这样?
2014,00000001,00000005
2014,00000009,00000007
2013,00000120,00000122
2013,00000124,00000125
方法
SQL> select b.fphm,min(b.kshm),max(b.kshm)
2 from (
3 select a.*,to_number(a.kshm-rownum) cc
4 from (
5 select * from t order by fphm,kshm
6 ) a
7 ) b
8 group by b.fphm,b.cc
9 /
--转自