急...SQL查询语句,单表,在线等,解决好就结分...
表:
ID CODE NUM
1 2000089 2
2 3000722 3
3 2000089 1
查询出结果为:
2000089
2000089
3000722
3000722
3000722
2000089
意思就是把CODE字段值列出NUM个数。
------解决方案--------------------select
a.CODE
from
表 a,
(select (select count(*) from sysobjects where id <=t.id) as NUM from sysobjects t) b
where
a.NUM> =b.NUM
order by
a.ID
------解决方案-------------------- create table T(ID int, CODE varchar(20), NUM int)
insert T select 1, '2000089 ', 2
union all select 2, '3000722 ', 3
union all select 3, '2000089 ', 1
declare @max int
select @max=max(NUM) from T
set rowcount @max
select ID=identity(int, 1, 1) into #T from syscolumns, sysobjects
set rowcount 0
select A.* from T A, #T B
where A.NUM> =B.ID
--result
ID CODE NUM
----------- -------------------- -----------
1 2000089 2
1 2000089 2
2 3000722 3
2 3000722 3
2 3000722 3
3 2000089 1
(6 row(s) affected)