Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想显示按添加日期升序排列的表格的最后 10 行。
我知道我可以select count(*) as total from tableName然后$offset = 10 - totalselect * from tableName order by dateadded asc limit 10 offset $offset
select count(*) as total from tableName
$offset = 10 - total
select * from tableName order by dateadded asc limit 10 offset $offset
注意:我需要反向显示结果,最旧的在顶部,最新的在底部,因此简单地按 desc 排序不会产生我需要的结果
这可以在一个查询中完成吗?
只需订购 DESC...
SELECT * FROM tableName order by dateadded DESC Limit 10
交换结果的顺序
SELECT * FROM ( SELECT * FROM tableName order by dateadded DESC Limit 10 ) r ORDER BY dateadded