我在工作中正在阅读一些旧代码,并注意到有多个代码有order by 1子句视图。这有什么作用? : R& b) \, Y/ L4 B$ X" o6 c5 n例子:% s# k! ^" H. M0 x' m6 c
Create view v_payment_summary ASSELECT 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; $ W. i8 Y6 X$ O7 w. Z 解决方案: + f" M, a: R( a
这: ! b6 o- B. F1 l" z1 k& t7 jORDER BY 1…被称为序数-基于数字代表SELECT定义中定义的列数列。在您提供的查询中,它说:. f$ \9 A. \: a$ g0 u
ORDER BY A.PAYMENT_DATE因为:6 P" d a- O) [% S+ h, H
[ol]这不是很明显/清楚, D& Z* l) B7 e3 p, P- W/ i
如果列顺序发生变化,查询仍然有效,因此您可能会对意外顺序进行排序[/ol]