Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. use plant_service;
  2. select o.user_id,u.first_name,count(i.id) as `orders` from users as u
  3. join orders o on o.user_id=u.id
  4. join plants_orders po on po.order_id=o.id
  5. join plants p on po.plant_id=p.id
  6. join info_plants ip on ip.plant_id=p.id
  7. left join orders i on i.user_id=u.id
  8. where (ip.genus="Begonia")
  9. group by first_name
  10. order by `orders` desc,first_name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement