我想了解this问题的解决方案。
我希望在SQL Server中使用的MySQL代码是:
SELECT * FROM users WHERE city_id=1 ORDER BY datejoined ASC LIMIT 20,10;
我可以使用更简单的解决方案吗?
(上面的代码中显然是'20'是一个参数,但我从应用程序代码执行此查询,所以我只能构建像...LIMIT " + ((page * 10) - 10) + ",10;";
这样的字符串。也就是说,不需要tsql参数传递语法。
答案 0 :(得分:0)
I am trying to understand the solution to this question
ROWNUMBER()是一个函数,它只是为每一行选择一个行号。
考虑这样,首先你的结果将被选择过滤where子条标准,然后一个额外的列将被添加到你的结果,而这个额外的列只有编号1,2,3 ....等等。
LIMIT
clause tells MYSQL to limit the number of rows returned. Same u can achieved using RowNumber() function, as now row number have been assigned to every row, u can tell SqlServer in where clause that only fethched rows with RowNumber less than 10. (u will have to use nested query)
答案 1 :(得分:0)
您的查询将如下所示
select * from ( select *, ROW_NUMBER() over (order by datejoined) _ROW_NUMBER from users where city_id = 1 ) a where _ROW_NUMBER between 20 and 30