So I am getting stock quote on a 1 min interval. However I am getting multiple record while the candle is updating so I need to query where the most recent createdDate is the closing candle for that second.
[
{
"SPFuture": {
"close": 4154.75,
"createdDate": "2023-05-15T01:28:40.7539802-07:00",
"date": "2023-05-15T01:28:00",
"high": 4154.75,
"id": "6461ed384b35b7a4e5bdcf74",
"low": 4154.25,
"open": 4154.5,
"volume": 106
}
},
{
"SPFuture": {
"close": 4154.75,
"createdDate": "2023-05-15T01:28:40.7518972-07:00",
"date": "2023-05-15T01:28:00",
"high": 4154.75,
"id": "6461ed384b35b7a4e5bdcf6e",
"low": 4154.25,
"open": 4154.5,
"volume": 108
}
},
{
"SPFuture": {
"close": 4154.75,
"createdDate": "2023-05-15T01:28:40.5053761-07:00",
"date": "2023-05-15T01:28:00",
"high": 4154.75,
"id": "6461ed384b35b7a4e5bdcf68",
"low": 4154.25,
"open": 4154.5,
"volume": 105
}
},
Getting timeout on this
SELECT spf.*
FROM SPFuture spf
JOIN (
SELECT createdDate,
date
FROM SPFuture ss
WHERE ss.date>='2023-05-15T00:00:00'
AND ss.date=spf.date
ORDER BY createdDate DESC
LIMIT 1) zz ON zz.createdDate=spf.createdDate
AND zz.date=spf.date
WHERE date>='2023-05-15T00:00:00'
ORDER BY date DESC