开发者

How to order by column A and then by column B?

How to write SQL so that the result can be ordered first by colum开发者_开发百科n A then by column B. Something like below:

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


ORDER BY col_A, col_B

The SQLite website has syntax diagrams explaining the SQL grammar supported by SQLite.


Just feed a comma separated list of columns to 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.


SELECT * FROM tbl WHERE predictor ORDER by col_A, col_B
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜