Skip to content
Advertisement

SQl query to show the most popular category in terms of sales quantity for each country and each gender in year XXXX

There are Three tables here Orders, Customers and Items.

Please tell me how to solve this. I have tried few combinations but were not successful. Thanks in advance.

Advertisement

Answer

In Mysql 8 you have ROW_NUMBER to select the “best” from a PARTITION

country   | gender | category   | oYear | total
:-------- | :----- | :--------- | ----: | ----:
Indonesia | m      | food       |  2020 |    39
Indonesia | m      | skincare   |  2020 |   300
Singapore | m      | sportswear |  2020 |    40

db<>fiddle here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement