summaryrefslogtreecommitdiff
path: root/rushs/data-clash/step-3/napoleon_synthesis.sql
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /rushs/data-clash/step-3/napoleon_synthesis.sql
add: graphs et rushs
Diffstat (limited to 'rushs/data-clash/step-3/napoleon_synthesis.sql')
-rw-r--r--rushs/data-clash/step-3/napoleon_synthesis.sql43
1 files changed, 43 insertions, 0 deletions
diff --git a/rushs/data-clash/step-3/napoleon_synthesis.sql b/rushs/data-clash/step-3/napoleon_synthesis.sql
new file mode 100644
index 0000000..f71dd09
--- /dev/null
+++ b/rushs/data-clash/step-3/napoleon_synthesis.sql
@@ -0,0 +1,43 @@
+CREATE VIEW napoleon_affair_view AS
+WITH count_report AS (
+ SELECT
+ location,
+ COUNT(*) AS total_reports
+ FROM napoleon_data.public_reports
+ GROUP BY location
+),
+persons_mention AS (
+ SELECT
+ location,
+ name AS person,
+ count(*) AS occ
+ FROM napoleon_data.public_reports
+ INNER JOIN napoleon_data.historical_people
+ ON details LIKE concat('%', name, '%')
+ GROUP BY location, name
+),
+most_mentioned AS (
+ SELECT
+ location,
+ person AS most_mentioned_person,
+ occ AS occurrences_most_mentioned_person,
+ row_number() OVER (PARTITION BY location ORDER BY occ DESC) AS rn
+ FROM persons_mention
+),
+unique_people_count AS (
+ SELECT
+ location,
+ COUNT(DISTINCT person) AS total_people_mentioned
+ FROM persons_mention
+ GROUP BY location
+)
+
+SELECT
+ rc.location,
+ total_reports,
+ total_people_mentioned,
+ most_mentioned_person,
+ occurrences_most_mentioned_person
+FROM count_report AS rc
+INNER JOIN unique_people_count AS uc ON rc.location = uc.location
+INNER JOIN most_mentioned AS mmmm ON mmmm.location = rc.location AND mmmm.rn = 1;