SQL执行顺序解析

2018-04-02更新:SQL执行顺序

写惯了Pythonv、Java、C代码,基本惯性思维都认为程序是按顺序一步步执行的,但是今天要讲的SQL比较特殊,希望多大家有帮助!

Example:这是错误的执行步骤

select id,user_id,count(*) as number from tablenaem where id>3 group by user_id order by number

(1) select

(2) from table

(3) where

(4) group by

(5) order by 

实际执行顺序

(1) from tablename

(2) where

(3)  group by

(4) select

(5)Having  (聚合输出)

(6) order by

所以,在写的时候,一定要小心,不然输出的表极大可能是错误的。

猜你喜欢

转载自blog.csdn.net/zehui6202/article/details/79787921