This repository was archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries.sql
More file actions
61 lines (47 loc) · 1.54 KB
/
queries.sql
File metadata and controls
61 lines (47 loc) · 1.54 KB
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
--
-- Various example queries
--
-- get all wallets for user_id = 9
SELECT u.collection_id as user_id, w.address as wallet_id FROM user as u
JOIN wallet_link as w ON u.collection_id = w.collection_id
WHERE user_id = 9;
-- get sum of wallet balance for user_id = 9
SELECT u.collection_id as user_id, sum(w.balance) as wallet_balance FROM user as u
LEFT JOIN wallet_link as w ON u.collection_id = w.collection_id
GROUP BY w.collection_id, u.collection_id
HAVING user_id = 9;
-- How many AGIX did one user use to vote for a question
SELECT u.collection_id, u.balance FROM user as u
-- # of people voted for proposal
SELECT question_id, count(collection_id) as votes FROM answer as a
GROUP BY question_id
where collection_id = 9;
SELECT tmp.votes, count(tmp.votes) FROM (
SELECT question_id, count(question_id) as votes FROM answer as a
GROUP BY question_id
) as tmp
GROUP BY tmp.votes
-- % of people voted for proposal
SELECT
question_id,
(COUNT(CASE WHEN answer <> 'skip' THEN 1 END) * 100.0) / COUNT(*) AS participation_percentage
FROM
answer
GROUP BY
question_id;
-- all valid votes (not skipped)
SELECT * FROM answer WHERE answer != 'skip';
-- all votes of user = 9
SELECT * FROM answer WHERE answer != 'skip' AND collection_id = 9;
-- average grade using square root voting
SELECT
question_id,
SUM(sqrt(total_balance) * CAST(answer AS INTEGER)) / SUM(sqrt(total_balance)) AS "average grade"
FROM
answer
WHERE
answer != 'skip'
GROUP BY
question_id
HAVING
question_id = 118;