Skip to content
Advertisement

How to group rows in SQL with a special condition?

I have a table like this in my database:

I have to write a SQL-Query that selects every month that does not contain “content” at least once. And it should only give out one line.

So the output should be like this:

How can I accomplish that with a SQL-Query? I tried to do that with the group by function, but could not get it working properly.

Advertisement

Answer

If you want only one row per person/month combination, then use aggregation. You have use a having clause to filter out the 'content' rows:

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