SQL Server查询启动,限制

时间:2011-11-21 12:03:39

标签: sql-server select limit

以下MYSQL查询的SQL Server等价物是什么:

  

SELECT id FROM products WHERE id =   '$ this-> idLIMIT 0,10

3 个答案:

答案 0 :(得分:3)

SELECT * FROM ( 
    SELECT id, ROW_NUMBER() OVER (ORDER BY id) as row  
        FROM products where myparam='shopkeeper'
) a WHERE a.row > 0 and a.row <= 10

答案 1 :(得分:3)

处理限额10,20

*重要使用'ORDER BY'

SELECT TOP 20 FROM products WHERE id NOT IN(SELECT TOP 10 id FROM products ORDER BY id) ORDER BY id

答案 2 :(得分:1)

您可以在MSSQL中使用TOP 10:

SELECT TOP 10 id FROM products WITH(NOLOCK) WHERE shopkeeper = '$this->shopkeeper'

如果你需要10-20岁,你需要Royi的答案。