我在 ASP.NET 中使用 ROW_NUM() 函数进行分页
SELECT row_num, expense_id,email, reason, amount,date,category_name,is_income
FROM
(
SELECT e.expense_id,e.email, e.reason, e.amount,e.date,c.category_name,e.is_income,
ROW_NUMBER() OVER(ORDER BY e.date DESC,e.expense_id) as row_num
FROM Expense e
JOIN Category c ON e.category_id = c.category_id
WHERE e.date >='5-1-2011' AND e.date<='5-31-2011'
) as ExpenseInfo
WHERE email='sample@domain.com'
但它返回了一个不一致的 row_num 列表(例如 1,3,4... 或 2,3,4...)。我怎么解决这个问题?
提前致谢。
我已经解决了我的问题
SELECT RowNum, expense_id, email, reason, amount, date, category_name, is_income
FROM
(
SELECT e.expense_id, e.email, e.reason, e.amount, e.date, c.category_name, e.is_income, Row_Number() OVER(ORDER BY date DESC) as row_num
FROM Expense e JOIN Category c
ON e.category_id = c.category_id
WHERE e.date >='5-1-2011' AND e.date<='5-31-2011' AND e.email='sample@domain.com'
) AS ExpenseInfo
WHERE row_num>=1 and row_num<=20