请教如下
一个表
单号
1
2
3我需要查询出来的结果,必须是5的倍数,如果不足5的倍数,就补加空行,例如 我查询出来的结果,如果是3条记录的话,就补两条数据,单号='空'例如:
1
2
3
空
空
一个表
单号
1
2
3我需要查询出来的结果,必须是5的倍数,如果不足5的倍数,就补加空行,例如 我查询出来的结果,如果是3条记录的话,就补两条数据,单号='空'例如:
1
2
3
空
空
declare @table1 table (id varchar(10))
insert into @table1
select 1 union select 2 union select 3 SELECT * FROM @table1
union all
select '空' from
(select row_number()over(order by getdate()) n from sys.columns) a
where n <= (select 5-(count(*))%5 from @table1)
二楼的高手, 你的代码 提示这个?
insert into @table1
select 1 union select 2 union select 3
Create table Nums(n int)
insert into Nums
select 1 union select 2 union select 3 union select 4 union select 5
--Nums是数字辅助表,很多地方都可以用,这里只有1-5,因为你的只需要这么多,实际上可以建一个1-10000甚至更多的
SELECT * FROM @table1
union all
select '空' from Nums
where n <= (select 5-(count(*))%5 from @table1)