Query editor
SELECTday,reciprocated_buys,unreciprocated_buys,self_buys,self_sales,normal_sales,defections,(reciprocated_buys + unreciprocated_buys + self_buys) as total_buys,reciprocated_buys*1.000 / (reciprocated_buys + unreciprocated_buys + self_buys)*1.000 as prop_three_three,self_buys*1.000 / (reciprocated_buys + unreciprocated_buys + self_buys)*1.000 as prop_self_buys,defections*1.000 / (defections + normal_sales + self_sales)*1.000 as prop_defectionsFROM(SELECTday,sum(CASE WHEN isBuy AND friend IS NOT NULL AND trader != subject THEN 1 ELSE 0 END) as reciprocated_buys,sum(CASE WHEN isBuy AND friend IS NULL AND trader != subject THEN 1 ELSE 0 END) as unreciprocated_buys,sum(CASE WHEN isBuy AND trader = subject THEN 1 ELSE 0 END) as self_buys,sum(CASE WHEN isBuy = FALSE AND trader = subject THEN 1 ELSE 0 END) as self_sales,sum(CASE WHEN isBuy = FALSE AND friend IS NULL AND trader != subject THEN 1 ELSE 0 END) as normal_sales,sum(CASE WHEN isBuy = FALSE AND friend IS NOT NULL AND trader != subject THEN 1 ELSE 0 END) as defectionsFROM (SELECTtrader,subject,isBuy,date_trunc('day', evt_block_time) as dayFROM friendtech_base.FriendtechSharesV1_evt_TradeWHERE ethAmount > CAST(0 as UINT256)) trades_1LEFT OUTER JOIN (SELECT DISTINCTtrader as friend,subject as three_three_subjectFROM friendtech_base.FriendtechSharesV1_evt_TradeWHERE ethAmount > CAST(0 as UINT256)) trades_2ON trades_1.trader = trades_2.three_three_subject AND trades_1.subject = trades_2.friendGROUP BY 1)