-
Notifications
You must be signed in to change notification settings - Fork 0
/
quest.queries.sql
64 lines (59 loc) · 1.54 KB
/
quest.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- WORKING COUNT
SELECT time, avg(count) AS holder_count FROM (
SELECT DISTINCT
timestamp AS time,
block,
count()
FROM holders
WHERE
block % 40 = 0
AND cast(symbol AS string) = '${token}'
GROUP BY time, block
)timestamp(time)
SAMPLE BY $__interval;
-- CUR PRICE
SELECT
timestamp AS time,
avg(priceToken) AS avg_price
FROM price
WHERE cast(symbol AS string) = '${token}'
AND $__timeFilter(timestamp)
SAMPLE BY $__interval;
-- NEW SCORE
SELECT time, avg(avg_score) avg_score FROM (
SELECT DISTINCT
timestamp AS time,
block,
avg(score.score) AS avg_score
FROM holders
JOIN score ON address
WHERE block % 40 = 0
AND score <= 2
AND cast(symbol AS string) = '${token}'
AND $__timeFilter(timestamp)
GROUP BY time, block
)timestamp(time)
SAMPLE BY $__interval;
--SAMPLE BY 1h;
-- OLD SCORE
SELECT
timestamp AS time,
avg(hs.score) AS score,
count() AS num
FROM holders
INNER JOIN (SELECT address, coalesce(score, 0) as score from holderscore where score < 2) as hs
ON hs.address = holders.address
WHERE cast(symbol AS string) = 'yfi'
AND $__timeFilter(timestamp)
SAMPLE BY $__interval;
-- OLD PRICE
SELECT
timestamp AS time,
avg(hs.score) AS score,
count() AS num
FROM holders
INNER JOIN (SELECT address, coalesce(score, 0) as score from holderscore where score < 2) as hs
ON hs.address = holders.address
WHERE cast(symbol AS string) = 'yfi'
AND $__timeFilter(timestamp)
SAMPLE BY $__interval;