本文介绍了需要帮助来解决此查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好 我有以下数据Hi allI have data like belowItemcode itemname price dept1 aa 100 ABC2 bb 200 DEF3 cc 300 ABC4 dd 400 CCA5 ee 500 DEF6 ff 600 CCA7 gg 99 CCA8 hh 80 ABC9 ii 114 DEF10 jj 677 DEF11 kk 432 CCA12 ll 223 ABC i想要每个部门的前三项。 请告诉我怎么做。 谢谢i want top 3 items from each dept.Please tell me how to do this.Thank you推荐答案--top 3 by itemnameSELECT *FROM ( SELECT ROW_NUMBER() OVER(PARTITION BY dept ORDER BY itemname) AS RowNo, Itemcode, itemname, price, dept FROM TableName) AS TWHERE RowNo<4--top 3 by priceSELECT *FROM ( SELECT ROW_NUMBER() OVER(PARTITION BY dept ORDER BY price) AS RowNo, Itemcode, itemname, price, dept FROM TableName) AS TWHERE RowNo<4 如需了解更多信息,请参阅: ROW_NUMBER() [ ^ ] 这篇关于需要帮助来解决此查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-22 13:47