我有三个sql表
Orders: Clients: Products:
id id id
product_id gender category_name
client_id city
我需要为按性别和城市分组的每个category_name输出前5个product_id。例如
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.
我怎么做到的?我是否需要将客户和产品加入订单,然后按类别,性别和城市分组,最后应用排序并限制为5?