Mysql query execution order

order:

  • FROM
  • JOIN
  • ON
  • WHERE
  • GROUP BY (从此处开始可以使用select中指定的别名)
  • AVG, SUM, MAX
  • HAVING
  • SELECT
  • DISTINCT
  • ORDER BY
select  
   sum(goods.number)  
from order 
left join goods on goods.order_id = order.id 
where 
  order.status=1 
  group by order.user_id 
  having order.add_time > '2019-08-27 00:00:00' order by goods.number desc

 

  • First order to obtain data from the Orders table inside
  • Then ligated into a field through the left join more tables and line appearances commodity
  • By screening out the order status where the data 1
  • by user group by group, to obtain the user's purchase quantity and
  • In the above screening data, select the data in order to create time after August 27, 2019 in
  • Finally, these data to get the final data results in descending order by number of items purchased

 

Guess you like

Origin www.cnblogs.com/UniqueColor/p/11417553.html