如果您使用的是Oracle,
嘗試
Select *
from
(SELECT
rownum rn, bill.bill_id, bill.total_price, bill.sell_time,
bill.user_id, login.username AS Expr1
FROM bill
INNER JOIN login ON bill.user_id = login.user_id)
Where rn <= 100;
它會得到第一個100行
對於SQL Server
SELECT * FROM (SELECT bill.bill_id, bill.total_price, bill.sell_time, bill.user_id, login.username AS Expr1 ,ROW_NUMBER() OVER (ORDER BY bill.bill_id) as rn FROM bill INNER JOIN login ON bill.user_id = login.user_id)
Where rn <= 100;
如果您有SQL Server的12
SELECT bill.bill_id, bill.total_price, bill.sell_time, bill.user_id, login.username AS Expr1 FROM bill INNER JOIN login ON bill.user_id =login.user_id ORDER BY bill.bill_id OFFSET 100 ROWS FETCH NEXT 100 ROWS ONLY
根據您使用的數據庫,添加'取首先行','限制',或'TOP '。 –
這確實取決於你正在使用的rdbms。對於access/ms sql,它是'select top n'。對於mysql,它是'select ..... limit n' –
我正在使用microsoft sql server。我能寫出這種表達方式的最佳方式是什麼? –