gpt4 book ai didi

php - 返回mySQL的最后两组记录

转载 作者:行者123 更新时间:2023-11-29 08:15:11 26 4
gpt4 key购买 nike

嗯,我是 MySQL 数据库的新手,我遇到了一个问题,我需要从表中获取最后两组记录(这些记录每周都会自动添加到该表中),我需要使用它来查找实体上周的增长。

任何人都可以帮忙吗?

这是我写的,我在本地主机上测试了它并且它有效:D,但是当我们在线安装它时,它崩溃了:(

select pages.*, new.* from (
select id, tableone.page_id, one, two,(two - one) as diff from
(SELECT id, page_id, likes as two FROM `page_records` WHERE id IN ( SELECT max( id ) FROM `page_records` GROUP BY page_id )) as tableone left join
(SELECT page_id , likes as one FROM `page_records` where id in ( SELECT max(id) FROM `page_records` where id not in (select max(id) from `page_records` group by page_id) group by page_id))
as tabletwo
on tableone.page_id = tabletwo.page_id
order by tableone.page_id asc) as new inner join pages on pages.id = new.page_id

提前致谢。

最佳答案

尝试: SELECT id, page_id, likes FROM page_records order by id desc limit 0, 2

关于php - 返回mySQL的最后两组记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20760140/

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