Query editor
WITH FilteredCasts AS (-- Step 1: Filter out only the casts of the specific user and derive the month earlySELECTc.fid,c.hash,c.text,c.timestamp,c.deleted_at IS NOT NULL AS deleted,date_trunc('month', c.timestamp) AS month,c.parent_url AS channelFROMdune.neynar.dataset_farcaster_casts cWHEREc.fid = {{fid}} -- Replace with the desired FID),EngagementMetrics AS (-- Step 2: Calculate the engagement metrics (likes, recasts, comments)SELECTfc.fid,fc.text,fc.timestamp,fc.deleted,fc.month,fc.channel,COUNT(DISTINCT r.hash) FILTER (WHERE r.reaction_type = 1) AS likes_count,COUNT(DISTINCT r.hash) FILTER (WHERE r.reaction_type = 2) AS recast_count,COUNT(DISTINCT c2.hash) AS comment_count -- Count comments using self-join on castsFROMFilteredCasts AS fcLEFT JOINdune.neynar.dataset_farcaster_reactions r ON fc.hash = r.target_hashLEFT JOINdune.neynar.dataset_farcaster_casts c2 ON fc.hash = c2.parent_hashGROUP BYfc.fid, fc.text, fc.timestamp, fc.deleted, fc.month, fc.channel),RankedCasts AS (-- Step 3: Rank the casts per month based on the engagement scoreSELECT*,ROW_NUMBER() OVER (PARTITION BY monthORDER BY (likes_count + recast_count * 2 + comment_count * 3) DESC) AS rankFROMEngagementMetrics)-- Step 4: Select top 5 casts per month for the specific userSELECTfid,timestamp,deleted,month,channel,likes_count,recast_count,comment_count,textFROMRankedCasts