在没有分组依据的聚合查询中,select list的表达式#2包含未聚合的列'a.b.id';

umuewwlo  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(329)

请帮我解决这个问题。我的代码:

$dn1 = mysqli_fetch_array(mysqli_query($con, '
select count(id) as recip
     , id as recipid
     , (select count(*) from pm) as npm 
  from users 
 where username="'.$recip.'"'
 ));

它给出了以下错误
错误:在没有分组依据的聚合查询中,选择列表的表达式#2包含未聚合的列“omapm.users.id”;这与sql\u mode=only\u full\u group by不兼容
请帮我纠正这个。谢谢!

mzsu5hc0

mzsu5hc01#

$dn1 = mysqli_fetch_array(mysqli_query($con, 
    'select count(id) as recip, id as recipid, 
        (select count(*) from pm) as npm 
    from users 
    where username="'.$recip.'"
    group by recipid, npm'));

无论如何,您不应该在sql命令中使用php var。。这样你就有被注射的危险。。您应该检查mysql驱动程序的预处理语句和绑定参数。。

相关问题