有大佬能帮忙看看这道题怎么写吗
sql吧
全部回复
仅看楼主
level 1
Please write a query to get the top 3 item_id (has most distinct order_ids) for each category and their order count together with its rank for each category.
Table: item_sales_information
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| item_id | int |
| order_id | int |
| category | varchar |
| sold_date | timestamp|
+-------------+----------+
Your query should return the following output for the above table:
+----------+---------------+------------+------+
| item_id | order_count | category | rank |
+----------+---------------+------------+------+
| t3902 | 2599 | Clothes | 1 |
| t7892 | 2320 | Clothes | 2 |
| t1829 | 1878 | Clothes | 3 |
| k1290 | 1299 | Shoes | 1 |
| k4729 | 872 | Shoes | 2 |
| k0173 | 729 | Shoes | 3 |
... |
+----------+---------------+------------+------+
2022年10月14日 08点10分 1
level 6
还需要嘛
2022年10月16日 14点10分 3
需要
2022年10月21日 07点10分
level 3
111111
2022年11月05日 02点11分 4
1