gpt4 book ai didi

MYSQL - ORDER BY 子句

转载 作者:行者123 更新时间:2023-11-29 04:22:35 25 4
gpt4 key购买 nike

我有一些这样的记录

id  name    sequence
------------------------
1 steve 3
2 lee 2
3 lisa 1
4 john 0
5 smith 0

我想显示如下记录

id  name
------------
1 lisa
2 lee
3 steve
4 john
5 smith

当我使用 order by 子句时,它显示为

name
----
john
smith
lisa
lee
steve

查询

SELECT name from tbl1 where 1 ORDER BY sequence ASC

最佳答案

SELECT name
FROM tbl1
ORDER BY sequence = 0,
sequence ASC

SELECT name
FROM tbl1
ORDER BY case when sequence <> 0 then 1 else 2 end,
sequence ASC

关于MYSQL - ORDER BY 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19677653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com