mysql 语句执行顺序

来源:互联网 发布:司法拍卖网络平台 编辑:程序博客网 时间:2024/05/21 17:08
  1. select[distinct]  
  2. from  
  3. join(如left join)  
  4. on  
  5. where  
  6. group by  
  7. having  
  8. union  
  9. order by  
  10. limit 
    1. select distinct sum(a.OrderPrice) As order1,sum(d.OrderPrice) As order2  
    2. from orders a  
    3. left join (select c.* from Orders c) d   
    4. on a.O_Id = d.O_Id  
    5. where a.Customer='Bush' or a.Customer = 'Adams' or a.Customer = 'Carter'  
    6. group by a.Customer  
    7. having sum(a.OrderPrice) > 1500  
    8. union  
    9. select distinct sum(a.OrderPrice) As order1,sum(e.OrderPrice) As order2  
    10. from orders a  
    11. left join (select c.* from Orders c) e   
    12. on a.O_Id = e.O_Id  
    13. where a.Customer='Bush' or a.Customer = 'Adams' or a.Customer = 'Carter'  
    14. group by a.Customer  
    15. having sum(a.OrderPrice) > 2000  
    16. order by order1  
    17. limit 1 

0 0