您有一个我需要LIMIT的SQL语句,并且无法正确获取语法!
$strSQL = 'SELECT * FROM BlogItem WHERE Blog_Live=1 LIMIT '.$rowsperpage.' OFFSET '.$offset.''; $objQuery = mssql_query($strSQL)
or die ("Error Query [".$strSQL."]");
有人能给我一些建议吗?
编辑:
我正在使用SQL Server 2008
试过这个:
$strSQL = "SELECT * FROM BlogItem WHERE Blog_Live=1 AND RowNum >= ".$offset." AND RowNum < ".$offset." + ".$rowsperpage."";
答案 0 :(得分:0)
SELECT * FROM <table>
ORDER BY <columns>
OFFSET <EXPR1> ROWS
FETCH NEXT <EXPR2> ROWS ONLY
示例:
SELECT * FROM t_book AS P
ORDER BY P.barcode
OFFSET 10 ROWS
FETCH NEXT 20 ROWS ONLY
或
;WITH Results_CTE AS
(
SELECT
Col1, Col2, ...,
ROW_NUMBER() OVER (ORDER BY SortCol1, SortCol2, ...) AS RowNum
FROM Table
WHERE <whatever>
)
SELECT *
FROM Results_CTE
WHERE RowNum >= @Offset
AND RowNum < @Offset + @Limit`