2014-10-31 16 views

回答

1

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 
+0

從答案[鏈接](http://stackoverflow.com/questions/4596467/order-of-execution-of-the-query),您對'Having'和不同的順序'小組由'。 – 2014-10-31 08:08:51

+0

在執行之前執行。 – 2014-10-31 08:39:24

+0

你確定嗎?根據我的經驗,我認爲'group by'在'having'之前執行。 – 2014-11-01 03:32:27