开发者

Sort mysql data by count and timestamp

I'm trying to have a 'trending' search terms spot on my site that returns both the searches with most counts, but only from the las开发者_运维技巧t 24 hours.

The query I'm using to return the searches with most counts is:

  SELECT searchstring 
    FROM trending 
ORDER BY count DESC 
   LIMIT 5

My table columns are:

  • id
  • searchstring
  • count
  • timestamp


SELECT searchstring 
FROM trending 
WHERE 
  timestamp > DATE_SUB(NOW(), INTERVAL 1 DAY)
ORDER BY count DESC 
LIMIT 5
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜