MySQL有limit语句,而SQL Server中没有,以下为类似功能实现
1、top n
java
# 取最近10个月数据
SELECT TOP 10 * FROM test
ORDER BY 月份 DESC;
2、ROW_NUMBER() + where子句
java
# 取最近10个月数据
SELECT * FROM
(
SELECT ROW_NUMBER()over(order by 月份 DESC) AS rm,* from test
) AS b
WHERE rm<=12
order by 月份