mysql 初级SQL / Dune Analytics

0lvr5msh  于 2023-03-28  发布在  Mysql
关注(0)|答案(1)|浏览(108)

我一直在玩沙丘分析,但似乎不能得到这个工作!
我已经设法过滤了一个钱包,以显示交易,显示出售的代币数量和相应的BNB接收(在我开始摆弄它之前,它一直在工作)。

我遇到的问题是当天加入相应的BNB价格(我想我需要执行INNER JOIN函数)。

基本上我想有四列日期|销售的水滴代币数量|收到BNB|BNB价格(当日)
最后这部分我完全卡住了!

WITH Drip_Data AS
(SELECT
  "bnb_amount" / 1e18 AS BNB_Received_Raw,
  "token_amount" / 1e18 AS Drip_Sold,
  DATE_TRUNC('day', evt_block_time) AS day
FROM
  drip."fountain_evt_onBnbPurchase"
WHERE
  buyer = '\xFdD4D2e4e3b344429107590c20BCf4B88281Da33'
),
BNB_Data AS (
SELECT BNB_USD_PRICE FROM dune_user_generated."bnb_price" AS BNB),

谢谢大家!

rkkpypqq

rkkpypqq1#

你是完全正确的,你需要做一个加入的BNB价格数据!在这里我选择做左加入

WITH drip_data AS
(
SELECT
    "bnb_amount" / 1e18 AS BNB_Received_Raw
    , "token_amount" / 1e18 AS Drip_Sold
    , DATE_TRUNC('day', evt_block_time) AS time
FROM
    drip."fountain_evt_onBnbPurchase"
WHERE
    buyer = '\xFdD4D2e4e3b344429107590c20BCf4B88281Da33'
)

, bnb_data AS 
(
SELECT 
    time
    , "bnb_usd_price"
FROM dune_user_generated."bnb_price"
)

SELECT 
    d.time as "DATE"
    , d.Drip_Sold as "No. Drip Tokens Sold"
    , d.BNB_Received_Raw as "BNB Received"
    , b.bnb_usd_price as "BNB Price"
FROM drip_data d
LEFT JOIN bnb_data b
ON d.time = b.time

我也保存了这个query on Dune
希望这就是你要找的!

相关问题