Query editor
WITH loan_profits AS (SELECTa.lienId,date_trunc('day', a.evt_block_time) AS day,d.name AS collection,CAST(a.loanAmount AS DOUBLE) / 1E18 AS loan_amount_eth,CAST(a.rate AS DOUBLE) / 1e4 AS loan_rate,a.borrower,a.lender,a.tokenId,(CAST(a.loanAmount AS DOUBLE) / 1E18) * (CAST(a.rate AS DOUBLE) / 1e4) AS interest_amount_ethFROMblur_ethereum.Blend_evt_LoanOfferTaken aLEFT JOINtokens_ethereum.nft d ON a.collection = d.contract_addressWHEREd.contract_address IN (X'524cab2ec69124574082676e6f654a18df49a048',X'bd3531da5cf5857e7cfaa92426877b022e612cf8',X'062e691c2054de82f28008a8ccc6d7a1c8ce060d')),loan_status AS (SELECTlp.collection,lp.day,COUNT(lp.lienId) AS open_loans,SUM(lp.loan_amount_eth) AS total_loan_amount_eth,COUNT(DISTINCT lp.borrower) AS unique_borrowers,COUNT(DISTINCT lp.lender) AS unique_lenders,COUNT(DISTINCT lp.tokenId) AS unique_tokens,CASE WHEN SUM(lp.loan_amount_eth) > 0 THEN AVG(lp.interest_amount_eth / lp.loan_amount_eth) * 100 ELSE 0 END AS average_apy_percentFROMloan_profits lpGROUP BYlp.collection, lp.day)SELECTday,collection,open_loans,total_loan_amount_eth,unique_borrowers,unique_lenders,unique_tokens,average_apy_percentFROMloan_statusORDER BYday ASC;