jackguy2023-07-27 03:44 PM
Updated 2023-10-31
99
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
›
⌄
with finalt as (
SELECT DISTINCT address
from crosschain.core.address_labels
WHERE label_type LIKE 'cex'
AND blockchain like 'bitcoin'
)
SELECT
*,
sum(net_inflow) over (ORDER by day) as total_btc_flow
FROM (
SELECT
day,
sum(CASE when tx_type LIKE 'out' then amount end) as outflow,
sum(CASE when tx_type LIKE 'in' then amount end) as inflow,
sum(CASE when tx_type LIKE 'in' then amount end) - sum(CASE when tx_type LIKE 'out' then amount end) as net_inflow
from (
SELECT
date_trunc('day', block_timestamp) as day,
'out' as tx_type,
sum(VALUE) as amount
FROM bitcoin.core.fact_inputs
WHERE PUBKEY_SCRIPT_ADDRESS IN (SELECT DISTINCT * from finalt)
AND block_timestamp > current_date - 90
GROUP BY 1
UNION
SELECT
date_trunc('day', block_timestamp) as day,
'in' as tx_type,
sum(VALUE) as amount
FROM bitcoin.core.fact_outputs
Run a query to Download Data