douhuifen9942 2016-09-15 19:38
浏览 51
已采纳

在此查询中无法使用mysql count

I have this query right now to grab comments on my website:

SELECT a.author_id, 
a.guest_username, 
a.comment_text, 
a.comment_id, 
u.pc_info_public, 
u.distro, 
a.time_posted, 
a.last_edited, 
a.last_edited_time, 
u.username, 
u.user_group, 
u.secondary_user_group, 
u.`avatar`, 
u.`avatar_gravatar`, 
u.`gravatar_email`, 
u.`avatar_uploaded`, 
u.`avatar_gallery`, 
u.pc_info_filled, 
ul.username as username_edited 
FROM `articles_comments` a 
LEFT JOIN `users` u ON a.author_id = u.user_id 
LEFT JOIN `users` ul ON ul.user_id = a.last_edited 
WHERE a.`article_id` = ? ORDER BY a.`comment_id` ASC LIMIT ?

I'm trying to add-in a COUNT(l.likes) from a table called "likes" (the "l" being what I name it when doing the ON check).

The problem is, when I add the COUNT in, my query instantly fails with an error like this:

Syntax error or access violation: 1140 In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'goltest.a.author_id'; this is incompatible with sql_mode=only_full_group_by

I've googled and googled and all the examples I can find to fix it don't make sense to me, can someone elaborate on the error?

  • 写回答

1条回答 默认 最新

  • dongyou9818 2016-09-15 19:42
    关注

    The error message tells you what's wrong: You need to group by something, to count how many likes that something has. The grouping is usually done on the primary key on which you're joining the tables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记