gpt4 book ai didi

mysql - sql中select语句中聚合函数可能的位置和执行顺序?

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

我可以在一个 SQL 查询中的什么位置放置聚合函数(在 select 子句、having 子句或其他子句中)。聚合函数在select语句的逻辑处理顺序中的执行顺序是怎样的?

帖子“Order Of Execution of the SQL query”没有涵盖函数的执行顺序。

最佳答案

1)子查询可以放在sql语句的Where、from和中间之后。

//After Where   
select * from orders where order_id in (select Oreder_id from OrderConfirmed)
// After From
Select * from (select * from table) a
//Middle of sql Statement
select id,(select Id from table1) form table2


2) You Can put Aggregation function in both select clause and having clause.

//In select
select count(employee) from employees group by employee_dept
//In having
select count(employee) from employees group by employee_dept having(max(salary)>2000)

3) order of execution of sql statement

1)From

2)Where

3)Group By

4)Having

5)aggregate Function

6)Select

关于mysql - sql中select语句中聚合函数可能的位置和执行顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26668801/

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