forked from ldbc/ldbc_snb_interactive_v1_impls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query1.sql
36 lines (36 loc) · 1.17 KB
/
query1.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
29
30
31
32
33
34
35
36
/* Q1. Posting summary
\set date '\'2011-07-21T22:00:00.000+00:00\''::timestamp
*/
WITH
post_count AS (
SELECT 0.0 + count(*) AS cnt
FROM post
WHERE 1=1
AND ps_creationdate < :date
)
, post_prep AS (
SELECT extract(year from ps_creationdate) AS messageYear
, ps_replyof IS NOT NULL AS isComment
, CASE
WHEN ps_length < 40 THEN 0 -- short
WHEN ps_length < 80 THEN 1 -- one liner
WHEN ps_length < 160 THEN 2 -- tweet
ELSE 3 -- long
END AS lengthCategory
, ps_length
FROM post
WHERE 1=1
AND ps_creationdate < :date
--AND ps_content IS NOT NULL
AND ps_imagefile IS NULL -- FIXME CHECKME: posts w/ ps_imagefile IS NOT NULL should have ps_content IS NULL
)
SELECT messageYear, isComment, lengthCategory
, count(*) AS messageCount
, avg(ps_length) AS averageMessageLength
, sum(ps_length) AS sumMessageLength
, count(*) / pc.cnt AS percentageOfMessages
FROM post_prep
, post_count pc
GROUP BY messageYear, isComment, lengthCategory, pc.cnt
ORDER BY messageYear DESC, isComment ASC, lengthCategory ASC
;