Query editor
with buy as (select "to" as address, sum(cast(value as double)) as bought, 0 as soldfrom erc1155_polygon.evt_TransferSingle bWHERE b.id = '39564169591817091141298233809353363875261914311124973205899846004803127743368'AND b.evt_block_time >= cast('2022-10-12' as DATE)group by 1),--union allsell as (select "from" as address, 0 as bought, sum(cast(value as double)) as soldfrom erc1155_polygon.evt_TransferSingle sWHERE s.id = '39564169591817091141298233809353363875261914311124973205899846004803127743368'AND s.evt_block_time >= cast('2022-10-12' as DATE)group by 1)selectb.address,b.bought,s.sold,b.bought-COALESCE(s.sold, 0) as held,(b.bought-COALESCE(s.sold, 0))*50 as early_points,--total holders of atleast 1(select count(*) from buy bleft join sell son b.address = s.addresswhere b.bought-COALESCE(s.sold, 0) > 0) as number_of_earlyfrom buy bleft join sell son b.address = s.addresswhere b.bought-COALESCE(s.sold, 0) > 0group by 1, 2, 3, 4order by held