[英]SQL select the top hashtags in the last 24 hour
This is my query这是我的查询
SELECT *
FROM posts
WHERE description like concat('%', :hashtag, '%')
ORDER BY STR_TO_DATE(time,'%d-%m-%Y %H:%i:%s') ASC
I would like to select from posts
the top hashtags only in the time
last 24 hours我想select仅
time
过去 24 小时内posts
热门主题标签
PHP TIME FORMAT STR_TO_DATE(time,'%d-%m-%Y %H:%i:%s')
PHP 时间格式
STR_TO_DATE(time,'%d-%m-%Y %H:%i:%s')
EXAMPLE例子
SELECT * FROM posts WHERE time >= NOW() - INTERVAL 1 DAY GROUP BY description HAVING like concat('%', :hashtag, '%')
To get amount of posts with one hashtag you need a GROUP BY
to be able to COUNT
them.要获得带有一个主题标签的帖子数量,您需要一个
GROUP BY
才能对它们进行COUNT
。 On the other hand sorting it by time makes no sense at all.另一方面,按时间排序完全没有意义。
It would look like this:它看起来像这样:
SELECT COUNT(*) as hashtag_count,hashtag FROM posts WHERE time >= NOW() - INTERVAL 1 DAY GROUP BY hashtag ORDER BY hashtag_count
You can add a LIMIT x
do the query.您可以添加一个
LIMIT x
进行查询。
To ensure that all "hashtags" are set within the specific date, you can add +,- day onto the date as well.为确保在特定日期内设置所有“主题标签”,您也可以在日期上添加 +,- 日。
As for the top results, is there something like a score that is given to them?至于排名靠前的结果,有没有给他们打分之类的东西?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.