forked from ldbc/ldbc_snb_interactive_v1_impls
-
Notifications
You must be signed in to change notification settings - Fork 1
/
query24.sql
28 lines (28 loc) · 959 Bytes
/
query24.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.ps_postid) AS messageCount
-- joining with post_tag multiplies message records, hence they are DISTINCT'ed when counting likes
, count(DISTINCT l.l_postid||','||l.l_personid) AS likeCount
, extract(YEAR FROM m.ps_creationdate) AS year
, extract(MONTH FROM m.ps_creationdate) AS month
, con.pl_name AS "continent.name"
FROM tagclass tc
, tag t
, post_tag mt
, post m LEFT JOIN likes l ON (m.ps_postid = l.l_postid)
, place cou -- country
, place con -- continent
WHERE 1=1
-- join
AND tc.tc_tagclassid = t.t_tagclassid
AND t.t_tagid = mt.pst_tagid
AND mt.pst_postid = m.ps_postid
AND m.ps_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
;