Skip to content
Advertisement

How to find maximum and value of column with the same column in postgres?

I want to find maximum value of the has_sold column in an specific province.For example in all rows with province = Tehran which row has the most has_sold value? This is my table:

I had tried this SELECT DISTINCT city, max(has_sold) FROM fp_stores_data_test GROUP BY city, but I’m not sure it’s right.

Advertisement

Answer

You can try the below one using row_number()

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