serhii.net

In the middle of the desert you can say anything you want

WHY IS THIS HERE DANGER

24 Jan 2023

DS Neo4j

Tasks:

  • show graph schema: !assets/2023-01-24-144129_916x532_scrot.png
  • 10 artists: !assets/2023-01-24-144430_905x590_scrot.png
  • artists of pop>=95 and their songs: !assets/2023-01-24-150118_903x542_scrot.png
    MATCH (t:Track) - [:FROM_ARTIST] -> (a:Artist) WHERE (a.popularity >=95) RETURN t,a
    
  • songs with pop.>95: !assets/2023-01-24-150437_916x415_scrot.png
  • ./., odered by popularity asc: !assets/2023-01-24-150607_932x438_scrot.png
    MATCH (t:Track) WHERE (t.popularity>95) RETURN t.name,t.popularity as popularity ORDER BY popularity asc
    
  • artists with 80<pop<85 desc: MATCH (a:Artist) WHERE (a.popularity>80) AND (a.popularity)<85 RETURN a.name,a.popularity ORDER BY a.popularity DESC
  • count artists: MATCH (t:Track) WHERE (t.popularity>90) RETURN count(t) as number: !assets/2023-01-24-151026_909x169_scrot.png
  • show as a graph songs in “mint”: MATCH (t:Track)-[:IN_PLAYLIST]->(n:Playlist {name:'mint'}) RETURN t
    1. Which artist contributed to Migos’ song “Walk it talk it” (drake): MATCH (n:Track {name:"Walk It Talk It"})-[:FROM_ARTIST]->(a:Artist) WHERE a.name <> "Migos" RETURN a
    1. nodes reachable in 1-2 hops through FOLLOWS from Karolina: !assets/2023-01-24-152309_848x549_scrot.png MATCH (u:User {name:"Karolina"}) -[:FOLLOWS*1..2]-(uu) RETURN u,uu (undirected edges)

Advanced:

  • Return all artists Daniel likes: MATCH (u:User {name:"Daniel"})-[:LIKES]->(t:Track)-[:FROM_ARTIST]->(a:Artist) RETURN DISTINCT a (18) !assets/2023-01-24-153203_916x599_scrot.png
  • 12: top-5 artists by num of songs + average popularity of songs of artists, decr order: MATCH (s:Track)-[:FROM_ARTIST]->(a:Artist) RETURN a,count(s) as num,avg(s.popularity) as avgpop ORDER BY num DESC LIMIT 5:!assets/2023-01-24-153546_899x587_scrot.png
  • 13: songs of Ed Sheeran and someone else: MATCH (aa:Artist)<-[:FROM_ARTIST]-(s:Track)-[:FROM_ARTIST]->(a:Artist {name:"Ed Sheeran"}) WHERE a<>aa RETURN DISTINCT s.name,aa.name: !assets/2023-01-24-154008_905x620_scrot.png
  • 14: w/ songs of the other artists: MATCH (ss:Track)-[:FROM_ARTIST]->(aa:Artist)<-[:FROM_ARTIST]-(s:Track)-[:FROM_ARTIST]->(a:Artist {name:"Ed Sheeran"}) RETURN ss.name,aa.name,s.name !assets/2023-01-24-154439_907x599_scrot.png (I removed the <> and DISTINCT part.)
  • 15: y+m when Karolina liked the most songs: MATCH (u:User {name:"Karolina"})-[l:LIKES]->(s:Track) RETURN l.since.month as month, l.since.year as year, count(l) as liked ORDER BY liked DESC:!assets/2023-01-24-155110_926x634_scrot.png
  • 16: artist that appears the most often in playlists with songs from before 2000: MATCH (a:Artist)<-[:FROM_ARTIST]-(s:Track)-[:IN_PLAYLIST]->(p:Playlist) WHERE s.release_date.year<2000 RETURN a.name,count(a.name) as how_often ORDER BY how_often DESC!assets/2023-01-24-155957_919x627_scrot.png
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus