首页 > 解决方案 > 如何使用周数和年份查找上一行

问题描述

标签: sqlsql-server

解决方案


ORDER and filter by the WEEKNUM + (YEARNUM * 52) as a single derived column instead of trying to apply some kind of AND/OR logic.

You might also use ROW_NUMBER() to create a cardinal column so you can easily get the previous row. Or you might look into using the LAG() function.


推荐阅读