2011-11-21 64 views
0

什么是SQL服务器相当于下面的MySQL查询:SQL Server查询开始,限制

SELECT ID FROM产品WHERE ID = “$这个 - > idLIMIT 0,10

+0

为什么盲目使用NOLOCK? http://stackoverflow.com/questions/7123036/is-there-a-way-to-get-different-results-for-the-same-sql-query-if-the-data-stays/7123084#7123084或http://stackoverflow.com/questions/3879822/is-nolock-the-default-for-select-statements-in-sql-server-2005/3879846#3879846 – gbn

回答

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

可以在MSSQL使用TOP 10:

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

如果从10-20需要,你会ñ引用了Royi的回答。

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