create table #tb(id int,count1 varchar(6),count2 int)
insert into #tb
select 1,'001', 700 union all
select 2,'002', 800 union all
select 3,'003', 900 union all
select 4,'004', 1000 union all
select 5,'005', 1100 union all
select 6,'006', 1200 union all
select 7,'007', 1300 union all
select 8,'008',1400
--查询
select *
from #tb a
,#tb b
where a.id = b.id-2
and (a.id+1)/2%2 <> 0
/*
id count1 count2 id count1 count2
----------- ------ ----------- ----------- ------ -----------
1 001 700 3 003 900
2 002 800 4 004 1000
5 005 1100 7 007 1300
6 006 1200 8 008 1400
(4 行受影响)
*/
SQL SERVER 多列显示
最新推荐文章于 2023-01-13 16:58:16 发布