Skip to content
Advertisement

SQL Select random rows partitioned by a column

I have a dataset looks like this

and i need a query which returns 2 random values from where country in (‘a’, ‘c’):

Advertisement

Answer

This should work:

Replace rand() with random() if you’re using Postgres or newid() in SQL Server.

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