gpt4 book ai didi

php - 在 php 中按升序排列的最后 20 个数据

转载 作者:可可西里 更新时间:2023-11-01 00:18:51 24 4
gpt4 key购买 nike

如何在php查询中获取数据库的最后20条数据,这些数据将按升序显示在数据库中?我问是因为如果我写 desc limit 20 那么它将首先显示最后的数据,最后显示最后的 20 个数据。现在如果我写 asc limit 20 那么它将给出表中的前 20 个数据。我正在使用查询select * from table_name order by id desc limit 20 最近 20 个数据。

最佳答案

SELECT * FROM
(
SELECT * FROM `table_name` ORDER BY `id` DESC LIMIT 20
)
AS temp
ORDER BY `id` ASC

选择最后20个,然后用asc排序

关于php - 在 php 中按升序排列的最后 20 个数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42642709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com