[英]select all the rows from my table except the first 20 rows
我想從我的表中選擇除前 20 行之外的所有行。 怎么可能? 總行數不是靜態的。
SELECT statistics_id,title, user_name FROM (
SELECT statistics_id,title, user_name FROM statistics ORDER BY statistics_id DESC
LIMIT(select count(*)from statistics )-20
) sub
ORDER BY access_statistics_id ASC
我知道 'LIMIT(select count(*)from statistics )-20' 不是正確的方法。 請幫忙。
文檔說( https://dev.mysql.com/doc/refman/5.5/en/select.html )如下:
要檢索從某個偏移量到結果集末尾的所有行,您可以為第二個參數使用一些大數字。 此語句檢索從第 96 行到最后一行的所有行:
SELECT * FROM tbl LIMIT 95,18446744073709551615;
所以你可以使用類似的東西
LIMIT 20, veryLargeNumber
嘗試這個
DECLARE v_max bigint unsigned default ~0;
SELECT statistics_id,title, user_name
FROM statistics
LIMIT 20, v_max;
編寫選擇查詢后,您只需包含,
LIMIT 21,100;
21-Offset 即您要從哪一行開始選擇和
100-是Limit[可以根據需要設置]
你實際上需要:
SELECT
statistics_id, title, user_name
FROM statistics
ORDER BY
statistics_id ASC
LIMIT 20, 18446744073709551615;
根據MySQL 文檔
要檢索從某個偏移量到結果集末尾的所有行,您可以為第二個參數使用一些大數字。 此語句檢索從第 96 行到最后一行的所有行:
SELECT * FROM tbl LIMIT 95,18446744073709551615;
如果您的表增長很快,則選擇所有行(前 20 行除外)並不是一個好主意。 在這種情況下,您應該批量查詢,並一次處理一部分條目,例如:
SELECT * FROM tbl LIMIT 20,120;
嘗試使用 LIMIT 語法的偏移選項。 您可以在http://dev.mysql.com/doc/refman/5.0/en/select.html閱讀有關 LIMIT 語法的更多信息。
SELECT `statistics_id`
, `title`
, `user_name`
FROM `statistics`
ORDER BY `statistics_id` ASC
LIMIT 20, 18446744073709551615
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.