MySQL,无法在简单查询中使用分组

时间:2019-02-01 07:35:44

标签: mysql

我有这个简单的查询

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函数时,它可以解决我的问题,但是那没有发生了,欢迎您的帮助

1 个答案:

答案 0 :(得分:0)

您可以在下面尝试-mysql中没有first()函数,可以改用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