| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1005 人关注过本帖
标题:有大佬能帮我看看这个怎么写吗
只看楼主 加入收藏
fuckamerica
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2022-10-14
收藏
 问题点数:0 回复次数: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 |
... |
+----------+---------------+------------+------+
搜索更多相关主题的帖子: Table for the rank query 
2022-10-14 14:55
秋末茗塘
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2022-12-15
收藏
得分:0 
SELECT item_id
      ,order_id AS order_count
      ,category
      ,ROW_NUMBER() OVER(PARTITION BY category ORDER BY order_id DESC) rank
FROM table_1
2022-12-15 16:20
快速回复:有大佬能帮我看看这个怎么写吗
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017463 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved