gpt4 book ai didi

sql - SQL 标准中的 GREATEST 和 LEAST

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

我的理解是 GREATEST() 和 LEAST() 不是 SQL 标准的一部分,但很常见。

我在想,有没有办法在 SQL 标准中克隆 GREATEST 的功能?

SELECT id, GREATEST(1,2,3,4,5,6,7) AS number FROM table

完整查询:
  SELECT SUBSTR(section,1,2) AS campus, 
AVG(GREATEST(maximum - enrolled, 0)) AS empty
FROM sectionrun
WHERE coursenumber = '105' AND subject = 'ENGL'
GROUP BY campus

最佳答案

GREATEST(1,2,3,4,5,6,7) AS number

可以变成
(select max(tmp) from (
select 1 tmp from dual
union all
select 2 tmp from dual
union all
select 3 tmp from dual
union all
select 4 tmp from dual
union all
select 5 tmp from dual
union all
select 6 tmp from dual
union all
select 7 tmp from dual
) ) AS number

关于sql - SQL 标准中的 GREATEST 和 LEAST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3794451/

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