好吧,我是MySQL数据库的新手,我遇到了问题,我需要从表中获取最后两组记录(记录每周自动添加到此表中)我需要用来查找实体在上周所做的增长。
任何人都可以帮助PLZ。
这是我写的,我在我的本地主机上测试它并且它有效: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
提前致谢。
答案 0 :(得分:2)
尝试:
SELECT id,page_id,喜欢FROM page_records
order by id desc limit 0,2
答案 1 :(得分:0)
试试这个:
SELECT * FROM table_name
ORDER BY id DESC
LIMIT 0, 2
谢谢!