gpt4 book ai didi

sqlite - 在sqlite中使其简单

转载 作者:行者123 更新时间:2023-12-03 15:30:43 25 4
gpt4 key购买 nike

这是我的sqlite声明:

select code ,  
case when (max(close)-min(close))/min(close)<0.1 then "grade1"
when (max(close)-min(close))/min(close) <0.2 then "grade2"
when (max(close)-min(close))/min(close) <0.3 then "grade3"
else "grade4" end as type;

(max(close)-min(close))/min(close)使用了3次,如何使我的查询语句更简单?

最佳答案

将计算结果放入子查询中:

SELECT code,
CASE WHEN CloseRatio < 0.1 THEN 'grade1'
WHEN CloseRatio < 0.2 THEN 'grade2'
WHEN CloseRatio < 0.3 THEN 'grade3'
ELSE 'grade4'
END AS type
FROM (SELECT code,
(MAX(close) - MIN(close)) / MIN(close) AS CloseRatio
FROM MyTable);

关于sqlite - 在sqlite中使其简单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13319143/

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