gpt4 book ai didi

MySQL,不能在简单查询中使用group by

转载 作者:行者123 更新时间:2023-11-29 16:21:33 25 4
gpt4 key购买 nike

我有一个简单的查询

select *, FIRST(m.id), MAX(mj.meeting_day) from Member m
left join SaveWork as s on s.member_id = m.id
left join Points as mp on mp.id = s.point_id
left join Aggr as mj on mj.id = mp.aggr_id
where m.congregation_id = 2
GROUP BY m.id

但是当我尝试执行它时,我得到

#1064 - Something is wrong in your syntax near '(m.id) from Member m
left join SaveWork as s on s.member_id = m.id
left join M' in line 1

我不知道为什么会发生这种情况,我认为这与此有关 Expression #24 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'sprawy.s.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ,我想当我使用 FIRST 时函数它将解决我的问题,但这并没有发生,欢迎任何帮助

最佳答案

你可以尝试下面 - first() 函数在 mysql 中不可用,你可以使用 limit 代替

select m.id, MAX(mj.meeting_day) from Member m
left join SaveWork as s on s.member_id = m.id
left join Points as mp on mp.id = s.point_id
left join Aggr as mj on mj.id = mp.aggr_id
where m.congregation_id = 2
GROUP BY m.id order by m.id
limit 1

关于MySQL,不能在简单查询中使用group by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54474912/

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