Skip to content
Advertisement

How to return records with a specific resolution (uniform distributed) of a dataset in SQL

I face a database with a lot of entries (~19 million). On my server queries take about 20 seconds and return a lot of results. But in the frontend (a chart) I don’t need every single row, so my idea is to return only 100 elements of the resulting rows. But not the 100 first or the 100 last: 100 uniformly distributed elements of those rows. In other words, I want to be able to specify a resolution of my data.

Here is some pseudocode.

Do you have any ideas on how to write the query for this? Is this even possible?

Advertisement

Answer

You can use analytical funcrion count and row_number as follows (please use functions and syntax according to your database):

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