jackguyflows by cex
Updated 2023-07-27
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
address as a1,
project_name
from crosschain.core.address_labels
WHERE label_type LIKE 'cex'
AND blockchain like 'bitcoin'
)
SELECT
PUBKEY_SCRIPT_ADDRESS,
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
PUBKEY_SCRIPT_ADDRESS,
'out' as tx_type,
sum(VALUE) as amount
FROM bitcoin.core.fact_inputs
-- LEFT outer JOIN finalt
-- on PUBKEY_SCRIPT_ADDRESS LIKE a1
WHERE PUBKEY_SCRIPT_ADDRESS IN (SELECT DISTINCT a1 from finalt)
AND block_timestamp > current_date - 5
GROUP BY 1
UNION
SELECT
PUBKEY_SCRIPT_ADDRESS,
'in' as tx_type,
sum(VALUE) as amount
FROM bitcoin.core.fact_outputs
-- LEFT outer JOIN finalt
Run a query to Download Data