gpt4 book ai didi

php - 在没有 GROUP BY 的聚合查询中,SELECT 列表的表达式 #2 包含非聚合列 'a.b.id' ;

转载 作者:行者123 更新时间:2023-11-30 21:40:10 26 4
gpt4 key购买 nike

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

$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.'"'
));

它给出以下错误

Error: In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'omapm.users.id'; this is incompatible with sql_mode=only_full_group_by

请帮我改正。谢谢!

最佳答案

$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 .. 这样你就有 sqlinjection 的风险.. 你应该检查你的 mysql 驱动程序以准备语句和绑定(bind)参数..

关于php - 在没有 GROUP BY 的聚合查询中,SELECT 列表的表达式 #2 包含非聚合列 'a.b.id' ;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52023926/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com