0

Where can I put aggregation functions in one SQL query (in the select clause, in having clause or others ). And What's the executing order of aggregation functions in the logical processing order of the select statement?

The post "Order Of Execution of the SQL query" there doesn't cover the functions' executing order.

Community
  • 1
  • 1
Yulong Ao
  • 1,199
  • 1
  • 14
  • 22

1 Answers1

1

1) You can put subquery after Where ,from and middle of the sql statement.

//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 
Gaurav Jain
  • 444
  • 3
  • 13