我正在阅读一些工作中的旧代码,并注意到有多个带有order by 1子句的视图。这有什么作用?
order by 1
例子:
Create view v_payment_summary AS SELECT A.PAYMENT_DATE, (SELECT SUM(paymentamount) FROM payment B WHERE PAYMENT_DATE = B.PAYMENT_DATE and SOME CONDITION) AS SUM_X, (SELECT SUM(paymentamount) FROM payment B WHERE PAYMENT_DATE = B.PAYMENT_DATE and SOME OTHER CONDITION) AS SUM_Y FROM payment A ORDER BY 1;
这:
ORDER BY 1
…被称为“序数”-数字代表基于SELECT子句中定义的列数的列。在您提供的查询中,它表示:
ORDER BY A.PAYMENT_DATE
不建议这样做,因为: