Question

I've got a series of mysql datapoints in table based on time. Assume the interval is 1 per second, with up to a limit of 30000 seconds available. The values are always the same or decreasing as the time value increases, and decrease in an exponentially decreasing manner (fast to start, then very slow toward the end). The exact rate is not set or known. So, for example:

duration_seconds, value
1,  900
2,  898
3,  897
...
1000, 300
1001, 300
1002, 299
1003, 299
...
15000,100
..
20000,99
..
30000,99

At first the numbers are always unique, or 1 unique value per second. In the middle there may be 30 unique values per minute. And at the end there may be 1 unique value per 30 minutes.

I'd like to determine the number of unique values per minute at enough ranges throughout to simulate this curve. I only need unique values stored, however I want to know the frequencies inserting all the data.

I'd like to use one query to basically do this, for time intervals up to 30000. Such as 300 seconds. And get the count of unique values at each range. Is there some sort of grouping method I can use?

SELECT 0,300,count(distinct value) FROM data WHERE duration_seconds >= 0 AND duration_seconds <= 300;
SELECT 300,600,count(distinct value) FROM data WHERE duration_seconds >= 300 AND duration_seconds <= 600;
SELECT 600,1200,count(distinct value) FROM data WHERE duration_seconds >= 600 AND duration_seconds <= 1200;
...

A subquestion may be, how do I determine ideal ranges based on the rate of change? For instance 0-300 is good to start, but 1200-3600 is probably better midway, and 20000-30000 is probably best to end, as the points eventually vary little.

No correct solution

OTHER TIPS

You should be able to do something like below to find values for a range of every 300 units

SELECT (duration-1) DIV 300 * 300 AS low
  , (duration-1) DIV 300 * 300 + 300 AS high
  , COUNT(DISTINCT value)
FROM data
GROUP BY low, high
ORDER BY low, high;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top