Skip to content
Advertisement

sql: query to find max count with extra columns as well

Input table:events

GOAL

  1. I want max(distinct user) grouped by month column.
  2. my final result need two columns one is month and another one is max_count

I need output similar to this

I followed some approach

Approach1:

if i follow this approach, it is just giving me only max_count but i need month column as well

I know we can use something like order by and limit to get the result. But i dont want that hacky way.

Can anyone suggest a solution for this?

Advertisement

Answer

Use a window function:


user is a reserved keyword in SQL and should be quoted (or better: find a different name)

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement