gpt4 book ai didi

android - SQL 按列排序,0 为异常(exception)

转载 作者:行者123 更新时间:2023-11-29 15:26:41 25 4
gpt4 key购买 nike

我有列:

CAT  | Val
------------
none | 0
high | 5
low | 100
med | 50

如您所见,数字越低类别越高。 (反逻辑)除了 0..

所以我想排序依据,以便获得正确的类别顺序。 (无、低、中、高)。

我希望它们按顺序排列:

CAT  | Val
------------
none | 0
low | 100
med | 50
high | 5

我试过这个,但它联合了,然后按顺序排序。每个选择周围的括号会导致错误。

SELECT cat,  an_int FROM CATS WHERE an_int = 0
UNION
SELECT cat, an_int FROM CATS WHERE an_int <> 0 ORDER BY an_int DESC

这给出:

CAT  | Val
------------
low | 100
med | 50
high | 5
none | 0

最佳答案

试试这个:

select * from CATS 
order by case when cat='none' then 0 else 1 end ,Val desc

关于android - SQL 按列排序,0 为异常(exception),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11843582/

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