-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathumip-16.sql
More file actions
29 lines (29 loc) · 732 Bytes
/
umip-16.sql
File metadata and controls
29 lines (29 loc) · 732 Bytes
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
WITH
cum_gas AS(
SELECT
CAST(gas_price AS int64) AS gas_price,
CAST(SUM(gas_used) OVER (ORDER BY gas_price) AS int64) AS cum_sum
FROM (
SELECT
CAST(gas_price AS int64) AS gas_price,
CAST(SUM(receipt_gas_used) AS int64) AS gas_used
FROM
`bigquery-public-data.crypto_ethereum.transactions`
WHERE block_timestamp
BETWEEN TIMESTAMP('2021-01-02 00:00:00', 'UTC')
AND TIMESTAMP('2021-02-01 00:00:00', 'UTC')
GROUP BY
gas_price)),
halfway AS (
SELECT
CAST(DIV(MAX(cum_sum),2) AS int64) AS halfway
FROM cum_gas)
SELECT
cum_sum,
gas_price
FROM cum_gas, halfway
WHERE
cum_sum > halfway.halfway
ORDER BY
gas_price
LIMIT 1;