select id from tb where id in( case when id>=1 and id<=3 then (id+2)/3*3-2 case when id>=15 and id<=24 then (id-15)/2*2+15 end)
哥们: 间隔两行取一行应该是 1,4,7,... select id from( select number+1 as id from master..spt_values where type='p' and number<24 )t where id=( case when id>=1 and id<=14 then (id+2)/3*3-2 when id>=15 and id<=24 then (id-14)/2*2+14 end) /* id ----------- 1 4 7 10 13 16 18 20 22 24(10 行受影响)*/
对了,既然是15至...间隔一行,那么15应该取上啊. select id from( select number+1 as id from master..spt_values where type='p' and number<24 )t where id=( case when id>=1 and id<=14 then (id+2)/3*3-2 when id>=15 and id<=24 then (id-15)/2*2+15 end) /* id ----------- 1 4 7 10 13 15 17 19 21 23(10 行受影响)*/
where id=(
case when id>=1 and id<=3 then (id+2)/3*3-2
case when id>=15 and id<=24 then (id-15)/2*2+15
end)
消息 156,级别 15,状态 1,第 4 行
关键字 'case' 附近有语法错误。如何改
where id in(
case when id>=1 and id<=3 then (id+2)/3*3-2
case when id>=15 and id<=24 then (id-15)/2*2+15
end)
间隔两行取一行应该是 1,4,7,...
select id from(
select number+1 as id from master..spt_values where type='p' and number<24
)t
where id=(
case when id>=1 and id<=14 then (id+2)/3*3-2
when id>=15 and id<=24 then (id-14)/2*2+14
end)
/*
id
-----------
1
4
7
10
13
16
18
20
22
24(10 行受影响)*/
select id from(
select number+1 as id from master..spt_values where type='p' and number<24
)t
where id=(
case when id>=1 and id<=14 then (id+2)/3*3-2
when id>=15 and id<=24 then (id-15)/2*2+15
end)
/*
id
-----------
1
4
7
10
13
15
17
19
21
23(10 行受影响)*/