forked from ldbc/ldbc_snb_interactive_v1_impls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bi-24.sql
28 lines (28 loc) · 978 Bytes
/
bi-24.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* Q24. Messages by Topic and Continent
\set tagClass '\'Album\''
*/
SELECT count(DISTINCT m.m_messageid) AS messageCount
-- joining with message_tag multiplies message records, hence they are DISTINCT'ed when counting likes
, count(DISTINCT l.l_messageid||','||l.l_personid) AS likeCount
, extract(YEAR FROM m.m_creationdate) AS year
, extract(MONTH FROM m.m_creationdate) AS month
, con.pl_name AS "continent.name"
FROM tagclass tc
, tag t
, message_tag mt
, message m LEFT JOIN likes l ON (m.m_messageid = l.l_messageid)
, place cou -- country
, place con -- continent
WHERE 1=1
-- join
AND tc.tc_tagclassid = t.t_tagclassid
AND t.t_tagid = mt.mt_tagid
AND mt.mt_messageid = m.m_messageid
AND m.m_locationid = cou.pl_placeid
AND cou.pl_containerplaceid = con.pl_placeid
-- filter
AND tc.tc_name = :tagClass
GROUP BY year, month, con.pl_name
ORDER BY year, month, con.pl_name DESC
LIMIT 100
;