Skip to content
Advertisement

How to pull 3 random records per category in Presto SQL?

I have the following table:

I want to write a query that gives random 3 names per each category.

Possible output for example can be:

I know it should be something like:

but I can’t find the proper syntax to do this. It gives me

Not a window function: random

Advertisement

Answer

Use row_number():

That is, the random() goes in the order by.

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