大家好,我正在使用这个 MYSQL 查询来获取当月上传者最多的用户和他们的图像浏览总数:
$current_month = date('Y-m-d', strtotime("first day of this month")) . ' 23:59:59';
$users = DB::query("SELECT * ,
COUNT(p.id) as numPics,
SUM(p.views) as totalViews
FROM
images p
INNER JOIN
users u
ON
p.user_id = u.id
WHERE
p.created_at >= \"$current_month\"
GROUP BY p.user_id
ORDER BY totalViews DESC LIMIT 10");
totalViews 返回每个用户所有图片的总浏览量的麻烦,我想要的是获取每个用户在当月上传的图片的总浏览量。谢谢 。