forked from ldbc/ldbc_snb_interactive_v1_impls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bi-3.sql
28 lines (28 loc) · 829 Bytes
/
bi-3.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
/* Q3. Tag evolution
\set year 2010
\set month 11
*/
WITH detail AS (
SELECT t.t_name
, count(DISTINCT CASE WHEN extract(MONTH FROM m.m_creationdate) = :month THEN m.m_messageid ELSE NULL END) AS countMonth1
, count(DISTINCT CASE WHEN extract(MONTH FROM m.m_creationdate) != :month THEN m.m_messageid ELSE NULL END) AS countMonth2
FROM message m
, message_tag mt
, tag t
WHERE 1=1
-- join
AND m.m_messageid = mt.mt_messageid
AND mt.mt_tagid = t.t_tagid
-- filter
AND m.m_creationdate >= make_date(:year, :month, 1)
AND m.m_creationdate < make_date(:year, :month, 1) + make_interval(months => 2)
GROUP BY t.t_name
)
SELECT t_name as "tag.name"
, countMonth1
, countMonth2
, abs(countMonth1-countMonth2) AS diff
FROM detail d
ORDER BY diff desc, t_name
LIMIT 100
;