以下是我的演示查询:分发一半的记录,然后将它们合并
select 1 as 'testrank', 'title1' as 'testtitle'
union all
select 2 as 'testrank', 'title2' as 'testtitle'
union all
select 3 as 'testrank', 'title3' as 'testtitle'
union all
select 4 as 'testrank', 'title4' as 'testtitle'
union all
select 5 as 'testrank', 'title5' as 'testtitle'
union all
select 6 as 'testrank', 'title6' as 'testtitle'
我要分发一半的记录,在这种情况下3,在两个独立的部分。为了演示目的,我写下了查询,这是所需的输出。
select 1 as 'testrank', 'title1' as 'testtitle', 4 as 'testrank2', 'title4' as 'testtitle2'
union all
select 2 as 'testrank', 'title2' as 'testtitle', 5 as 'testrank2', 'title5' as 'testtitle2'
union all
select 3 as 'testrank', 'title3' as 'testtitle', 6 as 'testrank2', 'title6' as 'testtitle2'
我用Pivot尝试使用rownumber,但不知何故,我无法实现所需的输出。 任何建议将受到欢迎。
在比数据库更高的层次上进行这种格式化会更好。 –
不要这样做!这是糟糕的模式设计。担心表示层中的布局,而不是数据层中的布局。 –