-1

我想获得设计总视图/图片数量的流行度:这是代码:

$users = DB::query("SELECT * ,
  COUNT(p.id) as numPics,
  SUM(p.views) as totalViews
  COUNT(p.views)/SUM(p.id) as popularity
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 popularity DESC LIMIT 10");

我收到此错误:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解在 'COUNT(p.views)/SUM(p.id) 附近使用的正确语法作为流行度

4

2 回答 2

4

您在以下内容后缺少逗号:

SUM(p.views) as totalViews
于 2013-04-29T15:14:19.513 回答
1
$users = DB::query("SELECT * ,
  COUNT(p.id) as numPics,
  SUM(p.views) as totalViews , 
  COUNT(p.views)/SUM(p.id) as popularity
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 popularity DESC LIMIT 10");
于 2013-04-29T15:18:02.290 回答