sql,按A列然后按B列排序


79

如何编写sql,以便可以首先按A列而不是按B列对结果进行排序。如下所示:

SELECT * FROM tbl WHERE predictor ORDER by col_A and ORDER by col_B

Answers:



22

只需将逗号分隔的列列表提供给ORDER BY:

SELECT * from table WHERE table.foo=bar ORDER BY colA, colB

ORDER BY子句使输出行进行排序。ORDER BY的参数是用作排序键的表达式列表。对于简单的SELECT,表达式不必是结果的一部分,但是在复合SELECT中,每个排序表达式必须与结果列之一完全匹配。每个排序表达式可以可选地后面跟着COLLATE关键字和用于对文本和/或关键字ASC或DESC进行排序以指定排序顺序的整理函数的名称。


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.