以下是我的演示查詢:分發一半的記錄,然後將它們合併
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,但不知何故,我無法實現所需的輸出。 任何建議將受到歡迎。
在比數據庫更高的層次上進行這種格式化會更好。 –
不要這樣做!這是糟糕的模式設計。擔心表示層中的佈局,而不是數據層中的佈局。 –