forked from oldshensheep/v2ex_scrapy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.sql
96 lines (79 loc) · 2.26 KB
/
query.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
select count(*)
from comment;
-- where create_at between strftime('%s', '2013-01-01') and strftime('%s', '2014-12-31');
select count(*)
from member;
select count(*)
from topic;
-- top comment by thank_count
select topic_id, c.id, thank_count
from comment c
left join topic t on t.id = c.topic_id
order by thank_count desc;
-- top topic by votes
select id, title, votes
from topic
order by votes desc;
-- top topic by clicks
select id, title, clicks
from topic
order by clicks desc;
-- top node
select node, count(node) as count
from topic
group by node
order by count desc;
-- comment number group by user
select commenter, count(commenter) as comment_count
from comment
group by commenter
order by comment_count desc;
-- topic number group by user
select author, count(author) as topic_count
from topic
group by author
order by topic_count desc;
-- topic number group by year
SELECT date,
SUM(topic_count) OVER (ORDER BY date ) AS cumulative_topic_count
FROM (SELECT strftime('%Y-%m', create_at, 'unixepoch') AS date, COUNT(*) AS topic_count
FROM topic
GROUP BY date)
ORDER BY date;
-- user number group by year
SELECT date,
SUM(user_count) OVER (ORDER BY date ) AS cumulative_user_count
FROM (SELECT strftime('%Y-%m', create_at, 'unixepoch') AS date, COUNT(*) AS user_count
FROM member
GROUP BY date)
ORDER BY date;
-- comment number group by year
SELECT date,
SUM(comment_count) OVER (ORDER BY date ) AS cumulative_comment_count
FROM (SELECT strftime('%Y-%m', create_at, 'unixepoch') AS date, COUNT(*) AS comment_count
FROM comment
GROUP BY date)
ORDER BY date;
-- new topic number group by year
SELECT strftime('%Y-%m', create_at, 'unixepoch') AS date, COUNT(*) AS topic_count
FROM topic
GROUP BY date;
-- new user number group by year
SELECT strftime('%Y-%m', create_at, 'unixepoch') AS date, COUNT(*) AS user_count
FROM member
GROUP BY date;
-- new comment number group by year
SELECT strftime('%Y-%m', create_at, 'unixepoch') AS date, COUNT(*) AS comment_count
FROM comment
GROUP BY date;
-- tag usage count
select t.value as tag, count(*) as count
from topic,
json_each(tag) as t
group by t.value
order by count desc;
-- node usage count
select node, count(*) as count
from topic
group by node
order by count desc;