0
在哪裏可以將聚合函數放在一個SQL查詢中(select
子句中,having
子句或其他)。在select語句的邏輯處理順序中,聚合函數的執行順序是什麼?sql中的select語句中可能的位置和執行有關聚合函數的順序?
該帖子「Order Of Execution of the SQL query」沒有涵蓋功能的執行順序。
在哪裏可以將聚合函數放在一個SQL查詢中(select
子句中,having
子句或其他)。在select語句的邏輯處理順序中,聚合函數的執行順序是什麼?sql中的select語句中可能的位置和執行有關聚合函數的順序?
該帖子「Order Of Execution of the SQL query」沒有涵蓋功能的執行順序。
1)你可以在sql語句的where,from和middle之後放置子查詢。
//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
從答案[鏈接](http://stackoverflow.com/questions/4596467/order-of-execution-of-the-query),您對'Having'和不同的順序'小組由'。 – 2014-10-31 08:08:51
在執行之前執行。 – 2014-10-31 08:39:24
你確定嗎?根據我的經驗,我認爲'group by'在'having'之前執行。 – 2014-11-01 03:32:27