首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

送分!该怎么处理

2012-01-21 
送分!!declare@ttable(idintprimarykey,colldecimal(10,2))insert@tselect1,26.21unionallselect2,4.21uni

送分!!
declare   @t   table(id   int   primary   key,coll   decimal   (10,2))
insert   @t   select   1,26.21
union   all   select   2,4.21

union   all   select   3,76.55
union   all   select   4,58.02
union   all   select   10,53.02

union   all   select   11,66.35
union   all   select   8,52.10
union   all   select   9,12.25

应该很简单,可我想半天没想出来       就是怎么选出中间那部分数据

[解决办法]
什么规律?


[解决办法]
select *
from @t
where id in (3, 4, 10)
[解决办法]
declare @t table(id int primary key,coll decimal (10,2))
insert @t select 1,26.21
union all select 2,4.21

union all select 3,76.55
union all select 4,58.02
union all select 10,53.02

union all select 11,66.35
union all select 8,52.10
union all select 9,12.25

seelct top 3 * from @t
where id not in (
select top 2 id from @t
)

[解决办法]
估计不能做到吧,id自动按照升序排列的,取不到
[解决办法]
id 即然是primary key,insert时已经排序了
你这个不加其它字段没办法的
[解决办法]
除非id不为主键,才可以
[解决办法]
SELECT TOP * FROM @t WHERE id NOT IN(SELECT TOP 2 id FROM @t)
[解决办法]
declare @t table(id int primary key,coll decimal (10,2))
insert @t select 1,26.21
union all select 2,4.21

union all select 3,76.55
union all select 4,58.02
union all select 10,53.02

union all select 11,66.35
union all select 8,52.10
union all select 9,12.25

DECLARE @COUNT INT
DECLARE @A INT
DECLARE @B INT
DECLARE @C INT

SELECT @COUNT = COUNT(*) FROM @t
SELECT @COUNT
SELECT @A = @COUNT/3 --- 上

IF (@COUNT%3 = 1)
BEGIN
SELECT @C = @A +1
SELECT @B = @A
END
ELSE
IF (@COUNT%3 = 2)
BEGIN
SELECT @B = @A+1
SELECT @C = @A+1
END
ELSE
IF (@COUNT%3 = 0)
BEGIN
SELECT @B = @A
SELECT @C = @A
END

SELECT @A ---- 上
SELECT @B ---- 中
SELECT @C -----下

select top @B * from @t where id not in ( select top @A id from @t)
[解决办法]
哦..不明你最后要的是什么

热点排行