34,587
社区成员
发帖
与我相关
我的任务
分享
DECLARE @intQuestionCount INT
SET @intQuestionCount=5 --数量条件
CREATE TABLE #t (id INT,
eCount INT
)
INSERT #t VALUES(1,1)
INSERT #t VALUES(2,2)
INSERT #t VALUES(3,1)
INSERT #t VALUES(4,3)
INSERT #t VALUES(5,1)
INSERT #t VALUES(5,2)
INSERT #t VALUES(6,1)
INSERT #t VALUES(7,4)
INSERT #t VALUES(8,2)
INSERT #t VALUES(9,1)
INSERT #t VALUES(10,1)
declare @tb table(num varchar(500),id int,eCount int)
insert @tb
select newid() as strID,id,eCount from #t
select SUM(eCount) from @tb c where @intQuestionCount>=(select sum(eCount) from @tb t where c.num >=t.num)
DROP TABLE [#t]
DECLARE @intQuestionCount INT
SET @intQuestionCount=5 --数量条件
CREATE TABLE #t (id INT,
eCount INT
)
INSERT #t VALUES(1,1)
INSERT #t VALUES(2,2)
INSERT #t VALUES(3,1)
INSERT #t VALUES(4,3)
INSERT #t VALUES(5,1)
INSERT #t VALUES(5,2)
INSERT #t VALUES(6,1)
INSERT #t VALUES(7,4)
INSERT #t VALUES(8,2)
INSERT #t VALUES(9,1)
INSERT #t VALUES(10,1)
select identity(int,1,1) as strID,id,eCount into #
from (select top 100 percent* from #t order by newid()) a
select * from #
select SUM(eCount) from # c
where @intQuestionCount>=(select sum(eCount) from # t where c.strID >=t.strID)
DROP TABLE [#t],#
DECLARE @intQuestionCount INT
SET @intQuestionCount=5 --数量条件
CREATE TABLE #t (id INT,
eCount INT
)
INSERT #t VALUES(1,1)
INSERT #t VALUES(2,2)
INSERT #t VALUES(3,1)
INSERT #t VALUES(4,3)
INSERT #t VALUES(5,1)
INSERT #t VALUES(5,2)
INSERT #t VALUES(6,1)
INSERT #t VALUES(7,4)
INSERT #t VALUES(8,2)
INSERT #t VALUES(9,1)
INSERT #t VALUES(10,1)
select identity(int,1,1) as strID,id,eCount into # from #t
select SUM(eCount) from # c
where @intQuestionCount>=(select sum(eCount) from # t where c.strID >=t.strID)
DROP TABLE [#t],#
/*
-----------
4
(所影响的行数为 1 行)
*/