本文介绍了如何为每个ID显示前3行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个查询,我只需要为每个子类别选择前3个产品。

我一直在尝试这种方式..

 选择  top   3  ROW_NUMBER() over  partition   by  Product,SubCategory  order   by  SubCategory  desc   RW 来自 ProductTable; 



但它没有相应的来。

如果我在代码中出错,请更正我。



需求额外支持:

产品 子类别 rw

1 - asdkfjkd - 1

2 - asdkfjkd - 1

3 - asdkfjkd - 1

4 - dkfjalsdkfj - 2

5 - dkfjalsdkfj - 2

6 - dkfjalsdkfj - 2

等......



---

在此先感谢:)

解决方案

Hi,
I have a query for which i need to select only the top 3 product for every subcategory.
I have been trying in this way..

select top 3 ROW_NUMBER()over ( partition by Product,SubCategory order by SubCategory desc) as RW from ProductTable;


but it is not coming accordingly.
Please correct me of where have i went wrong in the code.

Req O/p:
product subcategory rw
1 -- asdkfjkd -- 1
2 -- asdkfjkd -- 1
3 -- asdkfjkd -- 1
4 -- dkfjalsdkfj -- 2
5 -- dkfjalsdkfj -- 2
6 -- dkfjalsdkfj -- 2
so on..

---
Thanks in Advance :)

解决方案


这篇关于如何为每个ID显示前3行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 23:50