Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify SQL queries in crypto tutorial part 2 to work with static crypto dataset #3668

Open
wants to merge 4 commits into
base: latest
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions tutorials/blockchain-analyze/analyze-blockchain-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,20 @@ fees to decrease.
tx_count as "tx volume",
average(stats_fee_sat) as fees
FROM one_hour_transactions
WHERE bucket > NOW() - INTERVAL '2 days'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-2 days')
jonatas marked this conversation as resolved.
Show resolved Hide resolved
ORDER BY 1;
```

1. The data you get back looks a bit like this:

```sql
time | tx volume | fees
time | tx volume | fees
------------------------+-----------+--------------------
2023-06-13 08:00:00+00 | 20063 | 7075.682450281613
2023-06-13 09:00:00+00 | 16984 | 7302.61716910033
2023-06-13 10:00:00+00 | 15856 | 9682.086402623612
2023-06-13 11:00:00+00 | 24967 | 5631.992550166219
2023-06-13 12:00:00+00 | 8575 | 17594.24256559767
2023-11-20 01:00:00+00 | 2602 | 105963.45810914681
2023-11-20 02:00:00+00 | 33037 | 26686.814117504615
2023-11-20 03:00:00+00 | 42077 | 22875.286546094067
2023-11-20 04:00:00+00 | 46021 | 20280.843180287262
2023-11-20 05:00:00+00 | 20828 | 24694.472969080085
...
```

Expand Down Expand Up @@ -212,7 +212,7 @@ transaction volume, along with the BTC to US Dollar conversion rate.
tx_count as "tx volume",
total_fee_usd / (total_fee_sat*0.00000001) AS "btc-usd rate"
FROM one_hour_transactions
WHERE bucket > NOW() - INTERVAL '2 days'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-2 days')
ORDER BY 1;
```

Expand Down Expand Up @@ -268,7 +268,7 @@ transactions in a block, the higher the mining fee becomes.
avg(tx_count) AS transactions,
avg(block_fee_sat)*0.00000001 AS "mining fee"
FROM one_hour_blocks
WHERE bucket > now() - INTERVAL '5 day'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
GROUP BY bucket
ORDER BY 1;
```
Expand Down Expand Up @@ -325,7 +325,7 @@ units, in which case it's impossible for a block to include more transactions.
avg(block_weight) as "block weight",
avg(block_fee_sat*0.00000001) as "mining fee"
FROM one_hour_blocks
WHERE bucket > now() - INTERVAL '5 day'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
group by bucket
ORDER BY 1;
```
Expand Down Expand Up @@ -383,7 +383,7 @@ few percentage points of overall revenue.
```sql
WITH coinbase AS (
SELECT block_id, output_total AS coinbase_tx FROM transactions
WHERE is_coinbase IS TRUE and time > NOW() - INTERVAL '5 days'
WHERE is_coinbase IS TRUE and time > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
)
SELECT
bucket as "time",
Expand Down Expand Up @@ -451,7 +451,7 @@ grow for individual blocks, and they could include even more transactions.
bucket,
stats_agg(block_weight, block_fee_sat) AS block_stats
FROM one_hour_blocks
WHERE bucket > NOW() - INTERVAL '5 days'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
GROUP BY bucket
)
SELECT
Expand Down Expand Up @@ -512,7 +512,7 @@ increase the time range.
average_y(rolling(stats_miner_revenue) OVER (ORDER BY bucket RANGE '12 hours' PRECEDING))*0.00000001 AS "revenue in BTC",
average_x(rolling(stats_miner_revenue) OVER (ORDER BY bucket RANGE '12 hours' PRECEDING)) AS "revenue in USD"
FROM one_hour_coinbase
WHERE bucket > NOW() - INTERVAL '5 days'
WHERE bucket > date_add('2023-11-22 00:00:00+00', INTERVAL '-5 days')
ORDER BY 1;
```

Expand Down
Loading