Skip to content
Advertisement

Count rows with same value while keeping columns

Lets say i have the following sql table:

How can i modify my select query to return my data with an additional column telling me the number of occurrences for each ID, while keeping the original columns collected? Which would result in this:

Query is this:

Advertisement

Answer

You can use window functions, if your database supports them. What you ask for is as simple as a window count:

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