我想选择一个 sql 表的最后 3 行。我知道我应该使用SELECT * FROM table ORDER BY DESC LIMIT 3
,但是这段代码的问题是它从最后选择行。例如,它选择 30,然后是 29,然后是 28。但是,我需要这些格式:28, 29, 30
. 有什么建议吗?
问问题
31857 次
7 回答
5
尝试这个:
SELECT * FROM (
SELECT * FROM reset ORDER BY id DESC LIMIT 3
) as r ORDER BY id
于 2013-08-24T16:08:29.097 回答
3
我希望这对您的问题有所帮助
select * from
(
select * from reset
order by id DESC LIMIT 3
) t
order by id ASC
于 2013-08-24T16:13:19.910 回答
1
尝试这样的事情: -
SELECT * FROM reset
WHERE username = '$table' ORDER BY id ASC LIMIT (FOUND_ROWS() - 3), 3
于 2013-08-24T15:28:49.870 回答
0
尝试
Select * from (SELECT * FROM Table_name ORDER BY Column_name DESC limit 0,3) as alias ORDER BY Column_name ASC;
于 2014-11-21T11:37:10.900 回答
0
怎么样:
select * from (select * from table order by x desc limit 3) order by x;
于 2013-08-24T15:28:27.417 回答
0
它将帮助您提供最新的 3 行数据,如果您想获取前 3 行,那么ASC
而不是DESC
.
select distinct column_name from Table order by column_name desc limit 3;
于 2021-08-12T05:19:19.333 回答
0
试试这个手册!
简单又简单!!
Select * From tableName where
PKCol=(select count(*) from tableName )
OR
PKCol=(select count(*) from tableName )-1
OR
PKCol=(select count(*) from tableName )-2
order by PKCol desc;
于 2017-08-28T16:45:37.077 回答