我有这个数据库:
Image : id,user_id,[..],created_at
Visit : id,image_id,created_at
user : id,[..]
我有这个查询来获取顶级上传者用户,
$current_month = date('Y-m-d', strtotime("first day of this month")) . ' 23:59:59';
$users = DB::query("SELECT * ,
COUNT(p.id) as numPics
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 numPics DESC LIMIT 10");
我所要做的就是加入访问表,这样我就可以在当前月份获得每个图像的总访问量。