0

I have three sql tables

Orders:       Clients:   Products:
id            id         id
product_id    gender     category_name
client_id     city

and i need to output top 5 product_id's for each category_name grouped by gender and city. For example

category1  category1  category1  category1
male       female     male       female 
city1      city1      city2      city2
top5       top5       top5       top5

category2  category2  category2  category2
male       female     male       female 
city1      city1      city2      city2
top5       top5       top5       top5
........................................
etc.

How do i get that? Do i need to left join clients and products to orders, then group by category, gender and city and finally apply sorting and limit to 5?

Superbman
  • 787
  • 1
  • 8
  • 24

0 Answers0