如何将UNION ALL联合查询的结果存入新表中并排序
联合查询语句如下
select ch1_201301.dt as dt, ch1_201301.tie as tie from ch1_201301 where ch1_201301.dt between '2013-01-01 15:00:00' and '2013-02-28 15:00:00' union all select ch1_201302.dt as dt, ch1_201302.tie as tie from ch1_201302 where ch1_201302.dt between '2013-01-01 15:00:00' and '2013-02-28 15:00:00'order by dt
以上语句查询正常且查询结果按dt升序排列,如何将以上联合查询语句插入新表后是按dt升序排列
试过
select * into newTable from (select ch1_201301.dt as dt, ch1_201301.tie as tie from ch1_201301 where ch1_201301.dt between '2013-01-01 15:00:00' and '2013-02-28 15:00:00' union all select ch1_201302.dt as dt, ch1_201302.tie as tie from ch1_201302 where ch1_201302.dt between '2013-01-01 15:00:00' and '2013-02-28 15:00:00'order by dt) 提示子查询不能使用order by
改为select * into newTable from (select ch1_201301.dt as dt, ch1_201301.tie as tie from ch1_201301 where ch1_201301.dt between '2013-01-01 15:00:00' and '2013-02-28 15:00:00' union all select ch1_201302.dt as dt, ch1_201302.tie as tie from ch1_201302 where ch1_201302.dt between '2013-01-01 15:00:00' and '2013-02-28 15:00:00') as AA order by AA.dt 查询结果没有按dt排序,是乱的,有时排序正确,有时排序不正确。
如何修改语句可实现联合查询语句插入新表中后是按dt升序排序的,谢谢了