日期:2014-05-18 浏览次数:20776 次
create table tb(卡种类 varchar(10),面值 int,卡号 varchar(20))
insert into tb values('电费卡' ,50  ,'00111111')
insert into tb values('电费卡' ,50  ,'00111112')
insert into tb values('电费卡' ,50  ,'00111113')
insert into tb values('电费卡' ,50  ,'00111114')
insert into tb values('移动卡' ,50  ,'10111110')
insert into tb values('移动卡' ,50  ,'10111111')
insert into tb values('移动卡' ,50  ,'10111112')
insert into tb values('移动卡' ,50  ,'10111113')
insert into tb values('电费卡' ,100 ,'0110111112')
insert into tb values('电费卡' ,100 ,'0110111113')
insert into tb values('电费卡' ,100 ,'0110111114')
go
select 卡种类 ,面值 ,count(1) 张数 ,min(卡号) 开始卡号 ,max(卡号) 结束卡号 from tb group by 卡种类 ,面值
drop table tb
/*
卡种类        面值          张数          开始卡号                 结束卡号                 
---------- ----------- ----------- -------------------- -------------------- 
电费卡        50          4           00111111             00111114
移动卡        50          4           10111110             10111113
电费卡        100         3           0110111112           0110111114
(所影响的行数为 3 行)
*/