在MySQL WHERE的麻烦 [英] trouble with WHERE in mysql
本文介绍了在MySQL WHERE的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我正在使用此MYSQL查询来获取本月最受欢迎的上载用户和这些图片的总观看次数:
hi guys im using this MYSQL query to get the top uploader users and the total of thier images views in the current month :
$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返回所有图片的视图总数的麻烦,我想要的是获取当月上载的图片的视图总数. 谢谢.
the trouble that the totalViews return the total of views of all pictures , what i want is to get the total of views of the pics uploaded in the current month . thanks .
推荐答案
在mysql中使用 MONTH(NOW())获取当月数据
Use MONTH(NOW()) in mysql for getting data for current month
p.created_at >= MONTH(NOW())
这篇关于在MySQL WHERE的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文