Skip to content
Advertisement

How to distinct with condition

I am working on T-SQL. I got a table like this.

I want to write a script that will give me only different “z” values for each “y” values. I can’t group by “y” only I got “Column ‘x’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.” error.

How can I fix this?

My outcome should be like this:

Advertisement

Answer

You can use row_number()

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