我有Informix代码:
select data as DATA from (
(select distinct('Date|Message_Type|Total') as data,0 as sort from dual)
union
(select 'dt: '||day||'|'||trim(msg_type)||'|'||nvl(round(total,2),0) as data,1 as sort from weekly_report_1)
)order by sort)
输出:
data1
Date|Message_Type|Total
dt: 02/10/2015|1440|0.00
dt: 02/10/2015|Total|-26290965.84
dt: 02/11/2015|1240|-23550538.87
dt: 02/11/2015|1440|0.00
dt: 02/11/2015|Total|-23550538.87
dt: 02/10/2015|1240|-26290965.84
dt: 02/12/2015|1240|-24181913.23
dt: 02/14/2015|Total|0.00
dt: 02/12/2015|1440|0.00
dt: 02/12/2015|Total|-24181913.23
dt: 02/13/2015|1240|-24611999.80
dt: 02/13/2015|1440|0.00
dt: 02/13/2015|Total|-24611999.80
dt: 02/14/2015|1240|0.00
dt: 02/14/2015|1440|0.00
当我尝试执行以下操作时:
select * from(
select data as DATA1 from (
(select distinct('Date|Message_Type|Total') as data,0 as sort from dual)
union
(select 'dt: '||day||'|'||trim(msg_type)||'|'||nvl(round(total,2),0) as data,1 as sort from weekly_report_1)
)order by sort) order by DATA1;
我得到了:
错误:常规错误。语法错误(状态:37000,本机代码:FFFFD4CC)
我需要对表格进行排序。
答案 0 :(得分:2)
您只能拥有一个ORDER BY子句。您不需要第二级子查询。
SELECT data AS Data1
FROM (SELECT DISTINCT('Date|Message_Type|Total') AS Data,
0 AS Sort
FROM dual
UNION
SELECT 'dt: '||day||'|'||trim(msg_type)||'|'||nvl(round(total,2),0) AS Data,
1 AS Sort
FROM weekly_report_1
) AS AnyName
ORDER BY Sort, Data1;
除非您有一个严重过时的(更换多年的替换版)Informix版本,否则您可以按照列表中的列表进行排序。如果你确实有一个足够古老的Informix版本,这不起作用,你也需要选择Sort
值。或者,您可以依赖于您正在使用的代码集中Date
之前的dt
,只需忽略Sort
上的排序。