This article is part of a series intended to show how to use Memgraph on real-world data to retrieve some interesting and useful information.
We highly recommend checking out the other articles from this series which are listed in our tutorial overview section.
WARNING - this tutorial could contain Game of Thrones spoilers.
Game of Thrones is an American fantasy drama television series created by David Benioff and D. B. Weiss for HBO. It is an adaptation of A Song of Ice and Fire, George R. R. Martin's series of fantasy novels, the first of which is A Game of Thrones. The Game of Thrones world is full of interesting characters, locations, scenarios, unexpected deaths, and plot twists.
Even though the COVID-19 pandemic hit the entire world in 2020 and is now starting to become one of the worst
years in recent history, 2019 was also a huge disappointment to all Game of Thrones fans. According to user reactions, a seven-year
build-up resulted in a poorly written ending of the last season and ruined the ending of one of the most popular shows on the planet.
Nonetheless, if you want to know how many characters would have survived if Jon Snow had stayed dead, which House had the best Kill/Death Ratio, or who was the biggest traitor in the show, you came to the right place!
Although the Game of Thrones TV show is based on a series of books, our graph database contains only characters from the previously mentioned TV shows as the books are still not finished. This tutorial would not be possible without data analyst David Murphy who shared his collection of on-screen deaths on this link. For more information, you can visit his blogpost with interactive analysis on the show deaths. We won't be working with kills and deaths that happened off-screen or were tied to the undead (wraiths). The dataset we used was slightly modified, in which columns "Episode Name" and "IMDb Rating" were added.
The model consists of the following nodes:
Characternode has a
nameattribute corresponding to the character's name (e.g.
Allegiancenode has a
nameattribute corresponding to the house name the character is loyal to (e.g.
Deathnode has an
orderattribute corresponding to the order in which the death happened in the show (e.g.
Episodenode has a
numberattribute corresponding to the number of episodes (e.g.
nameattribute corresponding to the name of the episode (e.g.
"Mothers Mercy") and
imdb_ratingepisode corresponding to the IMDB rating of the episode (e.g. "9.1")
Seasonnode has a
numberattribute corresponding to the number of the season (e.g.
Locationnode has a
nameattribute corresponding to the location's name (e.g.
Nodes are connected with the following edges:
:KILLED- connect two Character nodes and they have 2 attributes,
methodwhich says how was the character killed (e.g.
countattribute representing a number of how many of these characters were killed (e.g. if
"Lannister soldiers"then on this edge
Allegiancenode representing an allegiance the character is loyal to
Deathnode in which death happened
:HAPPENED_IN- connects node
Locationnodes representing details of the death
Seasonnode which episode is part of
You have two options for exploring this dataset.
If you just want to take a look at the dataset and try out a few queries, open
Memgraph Playground and continue with
the tutorial there. Note that you will not be able to execute
On the other hand, if you would like to add changes to the dataset, download the
Memgraph Lab desktop application and navigate
Datasets tab in the sidebar. From there, choose the dataset
Game of Thrones deaths and continue with the tutorial.
In the queries below, we are using Cypher to query Memgraph via the console.
Here are some queries you might find interesting:
MINI-GAME - If you have watched the TV Show, try to guess each result before executing the query! 1) Let's start with a couple of simple queries. List the locations where most deaths occurred. Can you guess which one is it?
2) Now that we have the location with the most deaths, let's list the episodes with the most deaths as well.
3) List the number of kills per season. If you have watched the show, you should be able to guess this one.
4) The most poorly rated season by far was the last one, but can you guess the best one?
Let's list the seasons by IMDB ratings. The problem we get with using the
avg() function is that it
gives us too many decimals, therefore a useful solution is given in this example using
5) There are many methods by which characters were killed such as sword or Dragonfire, but let's list victims of unique methods.
6) Daenerys Stormborn of House Targaryen, the First of Her Name, Queen of the Andals and the First Men, Protector of the Seven Kingdoms, the Mother of Dragons, the Khaleesi of the Great Grass Sea, the Unburnt, the Breaker of Chains or shortened to "Daenerys Targaryen" in our database is the biggest killer on the show. Let's list all the episodes she killed in as well as characters she killed.
7) Houses or allegiances are one of the main aspects of Westeros. Some houses killed more characters
than others, but that doesn't matter in the end, what matters is efficiency. Let's list the allegiances with
the best Kill/Death Ratios or KDR for short. Here we came across one additional problem. If an allegiance had more
deaths than kills, the KDR would be 0. This can easily be fixed with the
8) One of the best-rated episodes, Battle of the Bastards, showed us a fight between two houses: Stark and Bolton. Let's see which one had more casualties.
9) One of the biggest features of Memgraph is drawing the graphs of queries we execute. Let's visualize all the
Loyalties with Characters. Execute the following query and head out to the
10) Remember that shocking last episode of the fifth season when they killed Jon Snow and we totally thought he was gonna stay dead? Well, let's list all the characters that would survive if he actually stayed dead.
11) If we want to see the above example in graph form, we have to add some modifications to
the query, such as saving paths to variables that could be then written in
12) Let's see how it looks like if we want to visualize all of Jon Snow kills with their locations.
13) Who do you think was the biggest traitor in terms of killing in its own allegiance? Well, let's check it out!
14) To visualize the last example, we have to add paths between nodes in the result.
15) Memgraph supports graph algorithms as well. Let's use Dijkstra's shortest path algorithm to show the most
gruesome path of kills. An example kill path is:
Jon Snow killed
Lannister Soldiers and they killed
Stark soldiers with total
To learn more about these algorithms, we suggest you check out their Wikipedia pages: