node 操作mysql如何 把查出的数据拼接成一个数据

如图 我查出电影数据后 因为类型 不止一条 所以返回了两行数据 这个数据 如何处理并且 使用? 我是想 node 返回 一条数据给前端 其中 类型 使用数组的形式

img

如果是只有类型不同的话,可以写成这样:
select m.*, GROUP_CONCAT(t.type_name) as type_name, c.country_name from movie m
left join movie_type mt on mt.movie_id = m.m_id
left join type t on t.type_id = mt.type_id
left join movie_country mc on mc.movie_id =  m.m_id
left join country c on c.country_id =  mc.country_id
where t.type_id in (4,5) and c.country_id in (2)

如果还有其他字段不同的话,那就把不同值得字段不取,或者也用group_concat合并一下就好了
  • 这篇文章:node操作mysql 也许有你想要的答案,你可以看看