Skip to content
Advertisement

Reverse group by and counts

I have tables for questions and answers. Each question can have 0 or multiple answers. When you left join the tables you get something like this:

What I need is the number of answers, and number of questions that have those many answers. i.e.,

What kind of SQL query in Redshift will solve this?

Advertisement

Answer

Another level of GROUP BY should do it:

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