从联合声明中删除默认订单(Remove default order by from union Statement)
我想显示这样的数据:
Column1 Column2 ----------------------- TotalAvg 60% A1 50% B1 70% Z1 60%我的SQL脚本是这样的:
select 'Total Avg' as Column1,'60%' as Column2 union select Column1,Column2 from tblAvg我得到的结果是这样的:
Column1 Column2 ------------------------ A1 50% B1 70% TotalAvg 60% Z1 60%问题:我想删除默认排序,并希望按照我们正在执行联合表的顺序得到结果。
I want to display data like this:
Column1 Column2 ----------------------- TotalAvg 60% A1 50% B1 70% Z1 60%My sql script is something like:
select 'Total Avg' as Column1,'60%' as Column2 union select Column1,Column2 from tblAvgand result I am getting is something like this:
Column1 Column2 ------------------------ A1 50% B1 70% TotalAvg 60% Z1 60%Question: I want to remove default ordering and want result in the order we are doing union tables.
最满意答案
SELECT * FROM ( select 0 as pos, 'Total Avg' as Column1, '60%' as Column2 union select 1 as pos, Column1, Column2 from tblAvg ) AS data ORDER BY pos, column1, column2 SELECT * FROM ( select 0 as pos, 'Total Avg' as Column1, '60%' as Column2 union select 1 as pos, Column1, Column2 from tblAvg ) AS data ORDER BY pos, column1, column2更多推荐
发布评论