我如何创建查询以在不计算重复项的情况下以沙丘上的以太坊上展示新创建的ERC-20合同的开发?

发布于 2025-02-13 11:02:59 字数 1323 浏览 0 评论 0原文

我正在尝试展示以太坊上新创建的ERC-20智能合约的开发。为此,我使用的是分析平台沙丘,该沙丘提供了几个用于SQL查询的数据库。

我的问题是以下问题:

我有一张表格显示特定合同的所有交易。每笔交易都由表的一行显示,并包含以下列“ date”,“ smart_contract_address”(唯一ERC20智能合约的标识符)和交易的其他详细信息作为“金额”

简化示例:

日期q1smart_contract_address
/2022250
BQ1/202220
CQ2/202210
AQ1/20225
AQ2/20227

我想计算不同的不同Smart_Contract_Addresses每季度。我想确保每个地址仅计数一次。计数地址后,它应该被“忽略”,不仅是在同一季度出现,而且在以下季度出现。

在我的示例中,我的预期查询结果看起来像:

QuarterCount
Q1/20222
Q2/20221,

但是我的查询并未显示我的预期结果。使用独特的关键字,我确保在每个季度中仅计算一次地址,但在以下几个季度中会再次计数...

您能告诉我如何调整我的查询,以至于我只计算一次相同的地址他们第一次出现的季度?

with everything as (
select contract_address as ca, date_trunc('quarter', evt_block_time) as time

from erc20."ERC20_evt_Transfer"
)

select time, count(distinct ca) as "Count"

from everything

group by time

I am trying to display the development of new created ERC-20 smart contracts on Ethereum. For this purpose I am using the Analytics platform Dune which provides a several databases for SQL querying.

My problem is the following one:

I have a table that shows all transactions of a specific contract. Every transaction is displayed by one row of the table and contains following columns "date", "smart_contract_address"(identifier for a unique ERC20 smart contract) and other details of the transaction as "amount"

Simplified example:

smart_contract_addressdateAmount
AQ1/202250
BQ1/202220
CQ2/202210
AQ1/20225
AQ2/20227

I would like to count the different smart_contract_addresses per quarter. I want to make sure that every address is only counted once. After an address was counted it should be "ignored", not only if it appeared in the same quarter, but also in following ones.

For my example my expected query result would look like:

QuarterCount
Q1/20222
Q2/20221

However my, query does not show my expected result. With the distinct keyword I make sure that in every quarter one address is only counted once, but will be counted again in the following quarters...

Can you tell me how I need to adjust my query that I count same addresses only once and for the quarter where they appeared for the very first time?

with everything as (
select contract_address as ca, date_trunc('quarter', evt_block_time) as time

from erc20."ERC20_evt_Transfer"
)

select time, count(distinct ca) as "Count"

from everything

group by time

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我偏爱纯白色 2025-02-20 11:02:59

尝试以下操作:

with everything as (
    select 
    contract_address as ca, 
    min(date_trunc('quarter', evt_block_time)) as time
    from erc20."ERC20_evt_Transfer"
    group by contract_address
)
select time, count(ca) as "Count"
from everything
group by time

try this:

with everything as (
    select 
    contract_address as ca, 
    min(date_trunc('quarter', evt_block_time)) as time
    from erc20."ERC20_evt_Transfer"
    group by contract_address
)
select time, count(ca) as "Count"
from everything
group by time
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文