由于ORDER BY语句,列已反转

时间:2011-10-21 13:57:53

标签: oracle

我正在使用以下代码编写报告:

SELECT SUBS_PROV "PROV", SUM(PAID_AMT), 0, 0, 0, SUM(PAID_AMT)
FROM H 
WHERE GRP = :P_POLICY AND 
&P_DATE BETWEEN :P_FROM_DATE AND :P_TO_DATE 
GROUP BY SUBS_PROV
UNION ALL

SELECT PROV "PROV", 0, SUM(PAID_AMT), 0, 0, SUM(PAID_AMT)
FROM D
WHERE GRP = :P_POLICY AND 
&P_DATE BETWEEN :P_FROM_DATE AND :P_TO_DATE 
GROUP BY PROV
UNION ALL

SELECT PROV "PROV", 0, 0, SUM(PAID_AMT), 0, SUM(PAID_AMT)
FROM E
WHERE GRP = :P_POLICY AND 
&P_DATE BETWEEN :P_FROM_DATE AND :P_TO_DATE 
GROUP BY PROV
UNION ALL

SELECT SUBS_PROV "PROV", 0, 0, 0, SUM(PAID_AMT), SUM(PAID_AMT)
FROM R 
WHERE GRP = :P_POLICY AND 
&P_DATE BETWEEN :P_FROM_DATE AND :P_TO_DATE 
GROUP BY SUBS_PROV

数据模型中的此查询中有一个TOTAL列,我必须添加“ORDER BY”,因为在Oracle 11g组下不再有效。

当我在最后添加“ORDER BY 1”并运行报告时,它会以总计TOTAL列的形式反转H的总数。有没有办法在不反转这些列的情况下添加ORDER BY?

谢谢!

1 个答案:

答案 0 :(得分:0)

您应该在每个ORDER BY之后添加GROUP BY,而不是仅在结尾处添加。{/ p>