Skip to content
Advertisement

Count occurrences in SQL

I have a table with the following data

And I would like to have for each ID how many occurrences of each type there are

Is there a way in SQL (something like a pivot table)

Advertisement

Answer

I would recommend conditional aggregation. This is a cross-database solution that is more flexible than vendor-specific solutions (and at least as efficient):

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