我有这个选择语句:
select m.title, m.category_code, c.company_name, wm_concat(d.director_name),
wm_concat(a.actor_name) as actors
from
actors a
inner join actor_in_movies aim
on aim.actor_id = a.actor_id
inner join movies m
on m.movie_id = aim.movie_id
inner join movie_directors md
on md.movie_id = m.movie_id
inner join directors d
on d.director_id = md.director_id
inner join companies c
on c.company_id = d.company_id
group by m.title, m.category_code, c.company_name;
它为每个演员返回相同的导演姓名一次……有什么办法可以解决这种情况吗?
也试过这个:
select m.title, cat.description, c.company_name, wm_concat(d.director_name),
wm_concat(a.actor_name) as actors
from
movie_categories cat
inner join movies m
on m.category_code = cat.category_code
inner join movie_directors md
on md.movie_id = m.movie_id
inner join directors d
on d.director_id = md.director_id
inner join companies c
on c.company_id = d.company_id
inner join actor_in_movies aim
on aim.movie_id = m.movie_id
inner join actors a
on a.actor_id = aim.actor_id
group by m.title, cat.description, c.company_name;
结果相同
编辑:猜猜我只是需要多想,用不同的,明白了!
select m.title, cat.description, c.company_name, wm_concat(distinct
d.director_name),
wm_concat(a.actor_name) as actors
from
movie_categories cat
inner join movies m
on m.category_code = cat.category_code
inner join movie_directors md
on md.movie_id = m.movie_id
inner join directors d
on d.director_id = md.director_id
inner join companies c
on c.company_id = d.company_id
inner join actor_in_movies aim
on aim.movie_id = m.movie_id
inner join actors a
on a.actor_id = aim.actor_id
group by m.title, cat.description, c.company_name;