简体   繁体   English

查找最近n个帖子中的用户帖子数

[英]Find the count of user posts in the last n Posts

I'm trying to find the most efficient way to find the number of posts by user in the last n rows of table .. I've tried 我试图找到最有效的方法来查找表的最后n行中用户的帖子数。

$db->query_first("SELECT COUNT(*) AS
user_recent_posts FROM " . TABLE_PREFIX . "post WHERE userid = $userid
AND threadid = '" . $threadinfo['threadid'] . "' AND visible = '1'
ORDER BY dateline DESC LIMIT 10" );

I'm trying to get the user posts in the last 10 posts in thread .. but this obviously returns last 10 posts by user regardless if they were in last 10 posts or not 我正在尝试在线程的最后10个帖子中获取用户帖子。但这显然按用户返回最后10个帖子,无论它们是否在最后10个帖子中

Use a subselect to first get the n rows and then count the ones from your user: 使用子选择首先获取n行,然后计算用户的行数:

$db->query_first("
  SELECT COUNT(b.*) AS user_recent_posts 
  FROM (
    SELECT a.* 
    FROM " . TABLE_PREFIX . "post a
    AND a.threadid = '" . $threadinfo['threadid'] . "' AND a.visible = '1'
    ORDER BY a.dateline DESC LIMIT 10) b
  WHERE b.userid = $userid" );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM