I have two columns in the database:
Value | Date
---------------------
1.3 | 1410374280000
Value is a float and Date is an epoch integer in milliseconds
I am trying to optimize this query as this returns a few thousand rows.
SELECT * FROM data WHERE date >= [some_time_in_the_past]
Since I am rendering a chart on the front end, I need far fewer data points. So I am truncating the date.
SELECT data.date / 5000 * 5000 AS truncated, data.price FROM data
WHERE date >= [some_time_in_the_past]
This above truncates the date to every 5 seconds. So now I want to SELECT DISTINCT
on it.
However:
SELECT DISTINCT truncated, price
This will SELECT DISTINCT on both the truncated_date as well as the price. Is there a way to only SELECT DISTINCT on the truncated date and get the price column too.