sql,按A列排序,然后按B列排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1698927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sql, order by column A and then by column B
提问by pierrotlefou
How to write the sql so that the result can be ordered first by column A than by column B. Something like below:
如何编写 sql 以便结果可以首先按 A 列而不是 B 列排序。如下所示:
SELECT * FROM tbl WHERE predictor ORDER by col_A and ORDER by col_B
SELECT * FROM tbl WHERE predictor ORDER by col_A and ORDER by col_B
回答by James McNellis
ORDER BY col_A, col_B
The SQLite website has syntax diagramsexplaining the SQL grammar supported by SQLite.
SQLite 网站有解释 SQLite 支持的 SQL 语法的语法图。
回答by meder omuraliev
Just feed a comma separated list of columns to ORDER BY:
只需将逗号分隔的列列表提供给 ORDER BY:
SELECT * from table WHERE table.foo=bar ORDER BY colA, colB
The ORDER BY clause causes the output rows to be sorted. The argument to ORDER BY is a list of expressions that are used as the key for the sort. The expressions do not have to be part of the result for a simple SELECT, but in a compound SELECT each sort expression must exactly match one of the result columns. Each sort expression may be optionally followed by a COLLATE keyword and the name of a collating function used for ordering text and/or keywords ASC or DESC to specify the sort order.
ORDER BY 子句导致对输出行进行排序。ORDER BY 的参数是用作排序键的表达式列表。对于简单的 SELECT,表达式不必是结果的一部分,但在复合 SELECT 中,每个排序表达式必须与结果列之一完全匹配。每个排序表达式可以有选择地跟在 COLLATE 关键字和用于排序文本和/或关键字 ASC 或 DESC 以指定排序顺序的整理函数的名称。
回答by Jason Leveille
SELECT * FROM tbl WHERE predictor ORDER by col_A, col_B