SQL中order by、group by 以及where的执行顺序

时间:2022-04-19 20:09:19
SELECT 
SUM(f_total),
t_order.f_customer_id,
f_sale_user_id,
f_delivery_time,
SUM(f_quantity),
f_name,
f_nick_name
FROM t_order 
JOIN t_order_detail ON t_order.f_order_id = t_order_detail.f_order_id 
JOIN`t_customer` ON t_order.f_customer_id=t_customer.f_customer_id
JOIN`t_user` ON t_order.f_sale_user_id=t_user.`f_user_id`
WHERE t_order.f_enterprise_id='8ca2ae12-04c2-4415-81b6-42f5ed6a5c54'
GROUP BY f_customer_id,f_sale_user_id
ORDER BY SUM(f_quantity) DESC

执行顺序

  1. where
  2. group by
  3. order by