Dune Analytics入门用例参考
查询1:以ETH计价筹集的资金
select SUM("value"/1e18) from ethereum.transactions \\ethereum.transactions表中的value列数值除以10的18次方
where "to" = '\x90B3832e2F2aDe2FE382a911805B6933C056D6ed' \\三个合约地址
or "to" = '\x3545192b340F50d77403DC0A64cf2b32F03d00A9'
or "to" = '\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'
查询 2a: 以当前ETH价值筹集的美元资金
select SUM("value"/1e18) * ( \\乘号后面大代码块
SELECT "price" FROM prices.usd \\从prices.usd表中选择 "price"列
WHERE "symbol" = 'WETH' \\在符号栏中过滤 "WETH"
AND "minute" < now() - interval '1 hours' \\只看过去1小时的时间条目
ORDER BY "minute" DESC \\时间降序
LIMIT 1 \\将查询限制在一个结果上(第一个结果,即最新价格)
)
from ethereum.transactions \\后面与查询1相同
where "to" = '\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'
or "to" = '\x3545192b340F50d77403DC0A64cf2b32F03d00A9'
or "to" = '\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'
查询2b: 以购买时ETH价值计算的美元筹集的资金
with poolyTransactions as \\定义poolyTransactions表
(
select
block_time, \\交易时间
value/1e18 as value_eth \\交易额
from ethereum.transactions \\后面与查询1相同
where "to" = '\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'
or "to" = '\x3545192b340F50d77403DC0A64cf2b32F03d00A9'
or "to" = '\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'
)
select \\创建输出内容
sum(value_eth * price) \\输出交易额和交易价格
from poolyTransactions
left join \\左表链接以下内容(左表为基表)
(select minute, price from prices.usd \\从prices.usd中创建表
where symbol = 'WETH' and minute > '2022-05-01')
as prices
on date_trunc('minute', block_time) = minute \\基于时间链接
详细分布输出展示如下:
查询 3: 支持者总人数
select COUNT(DISTINCT "from") from ethereum.transactions where "to" = '\x90B3832e2F2aDe2FE382a911805B6933C056D6ed' or "to" = '\x3545192b340F50d77403DC0A64cf2b32F03d00A9' or "to" = '\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'