我不是数据库专家,这肯定是一个新手问题。
我有一个包含有关电影数据的SQLite数据库。
主表(电影)包含:
然后我有演员表:
然后我有强制表:
在一个查询中,我应该检索给定影片的所有字符(在应用程序级别我是当前电影的id开始),演员的姓名和电影列表(!=这个当前的电影)演员扮演角色:
Character_name | Actor | Other movies where we've seen this actor
Mrs Doubtfire | Robin Williams | Mork & Mindy, Dead Poets Society, ...
Other name | Other actor | Related movies,...
这可能吗?怎么样?
答案 0 :(得分:2)
尝试:
select max(c.character_name) character_name,
max(a.name) || ' ' || max(a.surname) actor,
group_concat(distinct m.title) other_movies
from cast c
join actors a on c.actor_id = a.actor_id
left join cast omc on c.actor_id = omc.actor_id and c.movie_id <> omc.movie_id
left join movies m on omc.movie_id = m.movie_id
where c.movie_id = ?
group by a.actor_id