日期:2014-05-18 浏览次数:20325 次
create table tb(employeeno varchar(10),consumemoney int, balancemoney int,date datetime,[count] int)
insert into tb values('0001',1, 10, '2007-10-01 10:05:02', 5 )
insert into tb values('0002',3, 50, '2007-10-01 10:10:23', 30)
insert into tb values('0001',2, 8, '2007-10-01 15:01:20', 6 )
insert into tb values('0001',1, 6, '2007-10-02 12:13:28', 8 )
insert into tb values('0001',2, 4 , '2007-10-05 08:09:43', 9 )
insert into tb values('0002',2, 48, '2007-10-06 19:23:00', 31)
insert into tb values('0002',5, 43, '2007-10-07 08:20:16', 32)
insert into tb values('0002',3, 10, '2007-10-08 17:10:40', 34)
insert into tb values('0002',2, 8, '2007-10-09 08:01:07', 35)
insert into tb values('0001',1, 3, '2007-10-09 16:38:16', 10)
go
select m.employeeno,m.[count]+1 缺号 from
(select px=(select count(1) from tb where employeeno=a.employeeno and [count] <a.[count])+1 , * from tb a) m,
(select px=(select count(1) from tb where employeeno=a.employeeno and [count] <a.[count])+1 , * from tb a) n
where m.employeeno = n.employeeno and m.px = n.px - 1 and m.[count] <> n.[count] - 1
drop table tb
/*
employeeno 缺号
---------- -----------
0001 7
0002 33
(所影响的行数为 2 行)
*/