What are best practices for sampling or plotting values from a database?
Suppose I have a database with a single table. Each row consists of only two things: a time and one or more values. Let's assume the time is not regularly distributed. That is to say, one row may be on Second 1, and the next row may be on Second 2, but the third row may be on Second 23. Let's also assume I want to collect a huge number of rows, anywhere from a hundred thousand to a hundred million.

Naturally, a great way to explore data like this is to plot it on a two-dimensional line graph, with time being the independent variable and each of the values in the rows being the dependent variable.

A naive approach to plotting the data is to pick a time range, and then simply retrieve all of the rows that occur within that range, then plot their values using some graphing software or library of some sort.

However, I can think of a number of scenarios where this is impractical. What if my query results in a huge number of rows in the result set, for instance? Is there a way to "sample" data from the database, knowing that there are a large number of rows and that they are not uniformly distributed in time?

In short, how do I sample data from a database table, for the purposes of graphing/plotting the data?

BONUS QUESTION! What if I want to make a cumulative plot, where the plotted value is the sum of all previous values?
What are best practices for sampling or plotting values from a database?
===

Suppose I have a database with a single table. Each row consists of only two things: a time and one or more values. Let's assume the time is not regularly distributed. That is to say, one row may be on Second 1, and the next row may be on Second 2, but the third row may be on Second 23. Let's also assume I want to collect a huge number of rows, anywhere from a hundred thousand to a hundred million.

Naturally, a great way to explore data like this is to plot it on a two-dimensional line graph, with time being the independent variable and each of the values in the rows being the dependent variable.

A naive approach to plotting the data is to pick a time range, and then simply retrieve all of the rows that occur within that range, then plot their values using some graphing software or library of some sort.

However, I can think of a number of scenarios where this is impractical. What if my query results in a huge number of rows in the result set, for instance? Is there a way to "sample" data from the database, knowing that there are a large number of rows and that they are not uniformly distributed in time?

In short, how do I sample data from a database table, for the purposes of graphing/plotting the data?

BONUS QUESTION! What if I want to make a cumulative plot, where the plotted value is the sum of all previous values?