奇偶行并排显示

来源:互联网 发布:java中如何使用debug 编辑:程序博客网 时间:2024/06/05 06:50

实现效果:

结果


相关代码:

DECLARE @count intset @count =(select count(*) From dic_sex_code)--偶数行if @count % 2 = 0 beginselect DISTINCT d1.*,d2.* from(select row_number() over(order by code) as num,* From dic_sex_code) as d1,(select row_number() over(order by code) as num,* From dic_sex_code) as d2where d1.num % 2 = 1 and d2.num % 2 = 0 and d1.num + 1 = d2.num end --奇数行 ELSE beginselect DISTINCT d1.*,d2.* from(select row_number() over(order by code) as num,* From dic_sex_code) as d1,(select row_number() over(order by code) as num,* From dic_sex_code) as d2where d1.num % 2 = 1 and d2.num % 2 = 0 and d1.num + 1 = d2.num UNION all select d3.*,'','','','','','' from(select row_number() over(order by code) as num,* From dic_sex_code) as d3wherenum = @countend

2 0