forked from ldbc/ldbc_snb_interactive_v1_impls
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery2.sql
More file actions
32 lines (32 loc) · 1.05 KB
/
query2.sql
File metadata and controls
32 lines (32 loc) · 1.05 KB
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
29
30
31
32
/* Q2. Top tags for country, age, gender, time
\set startDate '\'2010-01-01T00:00:00.000+00:00\''::timestamp
\set endDate '\'2010-11-08T00:00:00.000+00:00\''::timestamp
\set country1 '\'Ethiopia\''
\set country2 '\'Belarus\''
*/
SELECT co.pl_name AS "country.name"
, extract(MONTH FROM p.ps_creationdate) as messageMonth
, cr.p_gender AS "person.gender"
, floor(extract(YEARS FROM age('2013-01-01'::date, cr.p_birthday))/5) AS ageGroup
, t.t_name AS "tag.name"
, count(*) AS messageCount
FROM post p
, post_tag pt
, tag t
, person cr -- creator
, place ci -- city
, place co -- country
WHERE 1=1
-- join
AND p.ps_postid = pt.pst_postid
AND pt.pst_tagid = t.t_tagid
AND p.ps_creatorid = cr.p_personid
AND cr.p_placeid = ci.pl_placeid
AND ci.pl_containerplaceid = co.pl_placeid
-- filter
AND co.pl_name in (:country1, :country2)
AND p.ps_creationdate BETWEEN :startDate AND :endDate
GROUP BY co.pl_name, messageMonth, cr.p_gender, t.t_name, ageGroup
HAVING count(*) > 100
LIMIT 100
;