gpt4 book ai didi

mysql - 使用mysql从表中获取下一个最后n个元素

转载 作者:太空宇宙 更新时间:2023-11-03 12:09:09 24 4
gpt4 key购买 nike

我有一个这样的表来跟踪每小时对我网站的访问:

id  | year | month | day | hour | date          | visit
1 1391 12 1 10 2012-11-10 15
... ... ... ... ... ... ...

我使用此查询来获取最近 7 天的访问者数量。

SELECT Sum(visit), `day`, `month`, `year`, WEEKDAY(date) as wd 
FROM tablename GROUP BY date ORDER BY date DESC LIMIT 7;

现在我的问题是:如何获取这 7 天之前的 7 天?

(年、日、月是我本地的日期格式,我想在注册时更改一次)

最佳答案

使用偏移:

SELECT Sum(visit), `day`, `month`, `year`, WEEKDAY(date) as wd 
FROM tablename
GROUP BY date
ORDER BY date DESC
LIMIT 7 OFFSET 7;

关于mysql - 使用mysql从表中获取下一个最后n个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25121976/

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