【发布时间】:2018-12-06 05:35:31
【问题描述】:
我有以下 mysql 查询
select m.flat_id,
f.flat_no,
fo.owner_name,
oc.occupant_name,
b.block_name,
f.floor_no,
f.floor_id,
m.user_id as user_map_id
from svk_apt_flats_users_mapping m
left join svk_apt_users u on u.user_id = m.user_id and u.association_id = 2
and u.customer_id = 2 and u.is_active = 1 and u.user_id is not null
left join svk_apt_flats f on f.flat_id = m.flat_id and f.is_active = 1
left join svk_apt_blocks b on b.block_id = f.block_id and b.is_active = 1
left join svk_apt_flat_owners fo on u.user_role_type_id = 4 and fo.is_active = 1 and fo.user_id = m.user_id
left join svk_apt_occupants oc on u.user_role_type_id = 5 and oc.is_active = 1 and oc.user_id = m.user_id
where f.block_id = 3
and m.user_id <> 2
and m.customer_id = 2
and m.association_id = 2
and m.is_active = 1
and m.is_active = 1
and (case when m.user_role_type_id = 5 then true else m.is_approved = 1 end)
我想将具有相同 'user_map_id' 的行聚合为一行。 mysql有什么解决方案吗?
【问题讨论】:
-
您还应该告诉我们您期望的输出,因为这可能会决定查询的内容。顺便说一句,您不需要发布如此复杂的查询;一个简化的版本就可以了,只要它可以传达你的观点。
-
预期输出是“显示重复的 'user_map_id' 并且它是一行中的行”。
-
如果您聚合或分组 user_map_id,您希望在查询中返回哪些其他列?就像你需要一些列或连接的总和?或其他任何东西。
-
是的,我需要连接子数组中具有相同 user_map_id 的行,就像“Postgresql 中的array_agg() 函数”一样
标签: mysql arrays aggregate sub-array