Struggling with a GROUP BY count

with this query,

const data = await db
  .select({
    ...getTableColumns(songHistory),
    count: sql<number>`cast(count(${songHistory.id}) as int)`,
  })
  .from(songHistory)
  .where(and(eq(songHistory.user_id, user!).if(typeof user === 'number'), gte(songHistory.played_at, from!).if(!!from)))
  .groupBy(songHistory.song_title)
  .orderBy(desc(songHistory.played_at));


i'm getting the error,

column "song_history.id" must appear in the GROUP BY clause or be used in an aggregate function


which i'm a bit confused on? i'm using the id col is in the aggregate function already
Was this page helpful?