gpt4 book ai didi

sql - 有没有其他合乎逻辑或更健壮的方式

转载 作者:行者123 更新时间:2023-12-04 18:20:31 25 4
gpt4 key购买 nike

我有一个 sql 查询

select count(salary)
from USER_DETAILS
where salary>0 and salary<1000 union all
select count(salary)
from USER_DETAILS
where salary>1000 and salary<10000 union all
select count(salary)
from USER_DETAILS
where salary>10000 and salary<100000

是否有任何其他逻辑或更健壮的方式来执行相同的查询(最好在 hql 中)。

提前致谢

最佳答案

试试这个,

SELECT  COUNT(CASE WHEN salary >= 0 and salary <= 1000 THEN salary END) "salary >= 0 and salary <= 1000",
COUNT(CASE WHEN salary >= 1000 and salary <= 10000 THEN salary END) "salary >= 1000 and salary <= 10000",
COUNT(CASE WHEN salary >= 10000 and salary <= 100000 THEN salary END) "salary >= 10000 and salary <= 100000"
from user_details

关于sql - 有没有其他合乎逻辑或更健壮的方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14930756/

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