怎样选出这样的记录?
我给学生编码这样:如:200501001代表2005级一班的001号学生,学生编码为001起始,完整编码为200501001,如果200501001与200501003之间没有学生,那么002这学号就没有人,怎样选出200501002这个学号?并且选之前要判断所有的学号是否中间有断开的,有的话就选出那个断的号码,而且要注意断开的学号如果有多个,那么就选出最小的那个?怎么办? 问题点数:0、回复次数:7Top
1 楼pengdali()回复于 2003-11-02 16:27:42 得分 0
select * from 表 where 编码+1 not in (select 编码 from 表)Top
2 楼pengdali()回复于 2003-11-02 16:29:19 得分 0
select * from 表 where 编码 like '200501%' and 编码+1 not in (select 编码 from 表)
and 编码 not in (select max(编码) from 表 where 编码 like '200501%')
Top
3 楼TripleH()回复于 2003-11-02 16:54:41 得分 0
我是想选出编码中差的那个编号,我也不知道是哪段之内有断开的号码!就是需要检查一下。Top
4 楼pengdali()回复于 2003-11-02 16:56:47 得分 0
select * from 表 where 编码+1 not in (select 编码 from 表)
and 编码 not in (select max(编码) from 表 where group by left(编码,6))Top
5 楼TripleH()回复于 2003-11-02 17:08:54 得分 0
我可能没有说清楚我的意思,我是想如果200101005与200501010之间缺号,没有200101006,200101007等这几个号码,怎样知道差这几个号码?并且用一个Edit1来显示,差的最小号码为200101006,就显示这个号码。如果号码段中如:200101001与200101045之间有几个缺口,怎么办?Top
6 楼pengdali()回复于 2003-11-02 17:13:23 得分 0
我写的就是当有几个缺口的时候把每个缺口的最小一个显示出来。Top
7 楼pengdali()回复于 2003-11-02 17:13:55 得分 0
如果你还要最小的:
select min(编码) 编码 from 表 where 编码+1 not in (select 编码 from 表)
and 编码 not in (select max(编码) from 表 where group by left(编码,6))
Top




