天天看點

查詢語句的執行順序

1  from  

2, join ..on

3,where,

4,group by 

5 having ,

6,select

7,distinct,

8,order by   

例如,查詢平均工資高于8000的部門的最高和最低 工資

select   max(sal),min(sal),depto  from emp   group by depto   having avg(sal)   >8000

先 from  emp表,有關聯 在關聯(join..on) ,然後  where條件,接着 group  by, having,  select ,