我如何加入两张桌子,然后根据sales_amount找到查找前5个CUSTMER_NAMES,并按Custmer名称进行分组
基本上,我希望由Custmer_name
with results as (
SELECT custmer_name, sales_amount from sales.customers inner join sales.transactions
on sales.customers.customer_code = sales.transactions.customer_code
)
select *, dense_rank() over(partition by custmer_name order by sales_amount desc) as ranking from results
<
a href =“ https://i.sstatic.net/in7tl.png” noreferrer”>交易表
custmer_name分组的最大sales_amount排名前5名。 https://i.sstatic.net/ilnzw.png“ rel =“ nofollow noreferrer“>加入后的结果
Basically I want the top 5 custmer_name with maximum sales_amount grouped by custmer_name
with results as (
SELECT custmer_name, sales_amount from sales.customers inner join sales.transactions
on sales.customers.customer_code = sales.transactions.customer_code
)
select *, dense_rank() over(partition by custmer_name order by sales_amount desc) as ranking from results
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该计算内部密集级别 cte或subquery,以及外部的过滤器:
You should compute the dense rank inside the CTE or subquery, and the filter on it outside: