WITH tagTab AS(
SELECT YearMonth, 
pm=RANK() OVER(PARTITION BY YearMonth ORDER BY amount DESC) 
FROM SaleTab
)
SELECT * FROM tagTab WHERE pm<=5

 开窗函数:

http://technet.microsoft.com/zh-cn/library/ms189461(v=sql.105).aspx

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2021-07-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案