Query editor
WITHbatch_data (batch_id, project_name, country, delivery_at, vintage, supplier) AS (VALUES(CAST(28 AS UINT256), 'GS12114: Energy-saving Stoves for a Clean Environment in Bangladesh', 'Bangladesh', DATE('2024-12-26'), 2023, 'SCB'),(CAST(29 AS UINT256), 'GS12114: Energy-saving Stoves for a Clean Environment in Bangladesh', 'Bangladesh', DATE('2025-12-25'), 2024, 'SCB')),batch_in AS (SELECT batchId AS "batch_id", SUM(amountIn) as "credits", SUM(amountOut/10e17)/SUM(amountIn) AS "crispc_per_credit"FROM solid_world_polygon.SolidWorldManager_evt_BatchCollateralizedGROUP BY batchId),batch_out AS (SELECT batchId AS "batch_id", SUM(amountOut) as "credits", SUM(amountIn/10e17)/SUM(amountOut) AS "crispc_per_credit"FROM solid_world_polygon.SolidWorldManager_evt_TokensDecollateralizedGROUP BY batchId),batch_table AS (SELECTbi.batch_id,bd.project_name,bd.vintage,CASE WHEN bo.credits IS NULL THEN bi.credits ELSE bi.credits-bo.credits END AS "credits",DATE_DIFF('day', DATE(NOW()), bd.delivery_at) AS "days_to_delivery",bi.crispc_per_credit,bd.country,bd.delivery_at,bd.supplierFROM batch_in biINNER JOIN batch_data bd ON bi.batch_id=bd.batch_idLEFT JOIN batch_out as bo ON bi.batch_id=bo.batch_id)SELECT * FROM batch_tableORDER BY batch_id