forked from ldbc/ldbc_snb_interactive_v1_impls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bi-1.sql
36 lines (36 loc) · 1.18 KB
/
bi-1.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
message_count AS (
SELECT 0.0 + count(*) AS cnt
FROM message
WHERE 1=1
AND m_creationdate < :date
)
, message_prep AS (
SELECT extract(year from m_creationdate) AS messageYear
, m_c_replyof IS NOT NULL AS isComment
, CASE
WHEN m_length < 40 THEN 0 -- short
WHEN m_length < 80 THEN 1 -- one liner
WHEN m_length < 160 THEN 2 -- tweet
ELSE 3 -- long
END AS lengthCategory
, m_length
FROM message
WHERE 1=1
AND m_creationdate < :date
--AND m_content IS NOT NULL
AND m_ps_imagefile IS NULL -- FIXME CHECKME: posts w/ m_ps_imagefile IS NOT NULL should have m_content IS NULL
)
SELECT messageYear, isComment, lengthCategory
, count(*) AS messageCount
, avg(m_length) AS averageMessageLength
, sum(m_length) AS sumMessageLength
, count(*) / mc.cnt AS percentageOfMessages
FROM message_prep
, message_count mc
GROUP BY messageYear, isComment, lengthCategory, mc.cnt
ORDER BY messageYear DESC, isComment ASC, lengthCategory ASC
;