我在工作中正在阅读一些旧代码,并注意到有多个代码有order by 1子句视图。这有什么作用?3 b4 n O7 x F, S. ~
例子: 2 j! F# x1 l: j4 u$ A/ s9 I) Y/ }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; 0 F; ]+ k" T& I解决方案: & @# e) p# L6 ]4 d& N3 b 这: : S( |1 N. e4 p2 }ORDER BY 1…被称为序数-基于数字代表SELECT定义中定义的列数列。在您提供的查询中,它说: & s9 I" \5 F; W/ y5 fORDER BY A.PAYMENT_DATE因为:2 Q. ?7 s+ M! f
[ol]这不是很明显/清楚 ! F P: ~: K4 v" D0 ~3 L" O如果列顺序发生变化,查询仍然有效,因此您可能会对意外顺序进行排序[/ol]