如何重写查询" 从tbl1中选择col1 ",以便将结果拆分为三列 - 每列垂直排序结果?
所以,如果我收到的数据是:
aaa bbb ccc ddd eee fff ggg
我需要查询将其返回为:
aaa ddd ggg bbb eee ccc fff
这可能吗?谢谢
实际上,这不应该在SQL中完成.除非aaa,ddd和ggg的配对有一些含义,否则这是客户端格式化,不应该在服务器上完成.
编辑:
为了智力锻炼的利益,这样的事情似乎有效.
select f1.data, f2.data, f3. data from (select data, ROW_NUMBER() over (order by data) as row_num from your_table) f1 left join (select data, ROW_NUMBER() over (order by data) as row_num from your_table) f2 on f2.row_num = f1.row_num + (select CEILING(COUNT(1) / 3) + 1 from your_table) left join (select data, ROW_NUMBER() over (order by data) as row_num from your_table) f3 on f3.row_num = f1.row_num + (select CEILING(COUNT(1) / 3) + 1 from your_table) * 2 where f1.row_num between 1 and FLOOR((select COUNT(1) from your_table) / 3) + 1
但是,我再次怀疑这是应该在客户端完成的事情,而不是在SQL中.