-
Notifications
You must be signed in to change notification settings - Fork 55
/
query.sql
102 lines (84 loc) · 2.6 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
97
98
99
100
101
102
SELECT (SELECT COUNT(*) FROM comment) AS 评论数,
(SELECT COUNT(*) FROM member) AS 用户数,
(SELECT COUNT(*) FROM topic) AS 主题数;
-- where create_at between strftime('%s', '2013-01-01') and strftime('%s', '2014-12-31');
-- top comment by thank_count
select topic_id, c.id, c.content, c.thank_count, c.no, t.title
from comment c
left join topic t on t.id = c.topic_id
order by c.thank_count desc;
-- top topic by thank_count
select id, title, votes
from topic
order by thank_count desc;
-- top topic by favorite_count
select id, title, favorite_count
from topic
order by favorite_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 as username, count(commenter) as comment_count
from comment
group by commenter
order by comment_count desc;
-- topic number group by user
select author as username, count(author) as topic_count
from topic
group by author
order by topic_count desc;
-- topic number group by year-month
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-month
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-month
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-month
SELECT strftime('%Y-%m', create_at, 'unixepoch') AS date, COUNT(*) AS topic_count
FROM topic
GROUP BY date;
-- new user number group by year-month
SELECT strftime('%Y-%m', create_at, 'unixepoch') AS date, COUNT(*) AS user_count
FROM member
GROUP BY date;
-- new comment number group by year-month
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;