-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries.sql
41 lines (38 loc) · 930 Bytes
/
queries.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
-- Posts with mosts upvotes
SELECT
TOP 100 *
FROM Posts p
WHERE
p.Tags LIKE '%docker%'
ORDER BY p.Score DESC
-- Posts with most upvotes on answer
SELECT
TOP 100 *
FROM Posts p
INNER JOIN Posts a ON a.Id = P.AcceptedAnswerId
WHERE
p.Tags LIKE '%docker%'
ORDER BY a.Score DESC
-- Posts with most views
SELECT
TOP 100 *
FROM Posts p
WHERE
p.Tags LIKE '%docker%'
ORDER BY p.Views DESC
-- Posts with most duplicates
SELECT
TOP 100 *
FROM Posts p
INNER JOIN
(SELECT COUNT(pd.Id) AS NumberOfChildren, JSON_VALUE(ph.Text, '$.OriginalQuestionIds[0]') AS OriginalPostId
FROM posts pd
INNER JOIN PostHistory ph on ph.postid = pd.id
WHERE pd.posttypeid = 1 -- q
AND ph.PostHistoryTypeId = 10 -- closed
AND ph.comment = 101 -- as duplicate
GROUP BY JSON_VALUE(ph.Text, '$.OriginalQuestionIds[0]')
HAVING COUNT(pd.Id) > 0) pd
ON pd.OriginalPostId = p.Id
WHERE p.Tags LIKE '%docker%'
ORDER BY pd.NumberOfChildren DESC