by seanhunter · 7y ago · 0 comments
with recursive bacon_movies as (
select
a.id as actor_id
, 0 as bacon_degree
from
actors a
where
a.name = 'Kevin Bacon'
union
select
r1.actor_id
, b.bacon_degree + 1 as bacon_degree
from
bacon_movies b
join roles r on r.actor_id = b.actor_id
join roles r1 on r.movie_id = r1.movie_id and r1.actor_id <> b.actor_id
where b.bacon_degree < 6
)
select
a.name
, min(b1.bacon_degree) as bacon_degree
from bacon_movies b1
join actors a on a.id = b1.actor_id
group by a.name
order by bacon_degree asc;
...not saying it's a good way to do thisIt really depends. If you do these kinds of queries all the time, it's a good idea to use a graph DB, but if these queries are rare, it often doesn't make sense to add a new technology to your project.
i've written thousands of lines of cypher queries. i just can't do sql though, it's not like i refuse either... it's that my brain just doesn't get it.
practice would surely help. i took an intro class once, and that improved my skills a lot (i.e. 0 -> 0.1)... teaching about the math of what's being done and giving me some ways to think about it... but it all just seems so incredibly tedious.