56,677
社区成员
发帖
与我相关
我的任务
分享
declare @a int
select @a=count(*) from tb
if @a<=100
select * from tb
else
select * from
(select *,row=row_number() over(order by id) from tb) where row%(@a/100)=1
declare @a int
select @a=count(*) from tb
if @a<=100
select * from tb
else if @a>100
select * from
(select *,row=row_number() over(order by id) from tb) where row%(@a/100)=1
IF ( SELECT COUNT(*)
FROM table1
) < 100
SELECT *
FROM table1
ELSE
BEGIN
;
WITH tmp
AS ( SELECT * ,
rn = ROW_NUMBER() OVER ( ORDER BY GETDATE() )
FROM table1
)
SELECT *
FROM tmp
WHERE rn % 2 = 1
END
IF ( SELECT COUNT(*)FROM table1) <= 100
SELECT * FROM table1
declare @Total int
select @Total=COUNT(1) from tb
if @Total<=100
begin
select * from tb
end
else
begin
;with t
(
select
px=row_number()over(order by (select 1)),
*
from
tb
)
select
[time],
value
from
t
where
px%2=1
end