I have a large of transctions daily on my table.
I wanted to only get the last transaction happened on that day.
I'm tying to copy this but I can't implement it on my own
here is my script
product_id = 30
date_track between '9/1/16' and '9/9/16'
If you have a column that specifies the ordering within a day, then you can do:
SELECT sh.* FROM (SELECT sh.*, ROW_NUMBER() OVER (PARTITION BY product_id, CAST(date_track as DATE) ORDER BY date_track DESC ) as seqnum FROM stocks_history WHERE product_id = 30 AND date_track between '2016-09-02' and '2016-09-05' ) sh WHERE seqnum = 1;
If you have another column that has the ordering, then use that for the