[英](MySQL) OrderBy Field1=3, Field2
I wish to order a table: 我想订购一张桌子:
Firstly by Field1=3 Then by Field2 DESC 首先按Field1 = 3,然后按Field2 DESC
I know I can't write OrderBy Field1=3, Field2 DESC 我知道我不能写OrderBy Field1 = 3,Field2 DESC
So how can I implement this?? 那么我该如何实现呢?
TO CLARIFY: 澄清:
Let's say I have a table of books. 假设我有一张桌子。 I wish to list ALL the books in the table. 我希望列出表中的所有书籍。 I wish the books from 1990 to appear at the top, then the rest of the books in alphabetical order of title. 我希望1990年以来的书排在顶部,然后其余书名按字母顺序排列。
Actually, you can write the statement you said you can't. 实际上,您可以写您说不能的声明。 Using your clarification example: 使用您的说明示例:
SELECT * FROM Books ORDER BY (year = 1990) DESC, name
"year = 1990" will be "1" for ones where year is 1990, so those will go at the top. 对于年份为1990的年份,“ year = 1990”将为“ 1”,因此它们将排在最前。
This is TSQL rather than MySQL, but it should give you the idea... 这是TSQL而不是MySQL,但它应该给您这个主意...
(Assuming I understand your question...) (假设我了解您的问题...)
ORDER BY
CASE WHEN Field1 = 3 THEN 0 ELSE 1 END ASC,
Field2 DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.