eferHeart Rate
Updated 2024-01-16
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
›
⌄
WITH WeeklyTransactions AS (
SELECT
DATE_TRUNC('week', BLOCK_TIMESTAMP) AS WeekStart,
COUNT(*) AS TransactionsCount
FROM aptos.core.fact_transactions
GROUP BY DATE_TRUNC('week', BLOCK_TIMESTAMP)
), WeekDurations AS (
SELECT
DATE_TRUNC('week', BLOCK_TIMESTAMP) AS WeekStart,
DATEDIFF(second, MIN(BLOCK_TIMESTAMP), MAX(BLOCK_TIMESTAMP)) AS WeekDurationSeconds
FROM aptos.core.fact_transactions
GROUP BY DATE_TRUNC('week', BLOCK_TIMESTAMP)
)
SELECT
ROW_NUMBER() OVER (ORDER BY wt.WeekStart) AS "Week No.",
CONCAT(
TO_VARCHAR(wt.WeekStart, 'YYYY-MM-DD'),
' to ',
TO_VARCHAR(DATEADD(second, wd.WeekDurationSeconds, wt.WeekStart), 'YYYY-MM-DD')
) AS "Range",
(wt.TransactionsCount / wd.WeekDurationSeconds) AS "Heart Rate",
TO_CHAR(DATE_TRUNC('month', wt.WeekStart), 'Mon YYYY') AS "Month"
FROM WeeklyTransactions wt
JOIN WeekDurations wd ON wt.WeekStart = wd.WeekStart
ORDER BY "Week No." DESC
QueryRunArchived: QueryRun has been archived