Trying to select the last 3 rows of a group. If I run this query
POST /_sql?format=txt
{
"query": "SELECT \"Samples.AccumulatedTime.@@data\",\"Samples.AccumulatedTime.name\",deviceName,timestamp FROM \"mtconnect-demo\" WHERE \"Samples.AccumulatedTime.name\" IN ('p1TotalOperatingTime', 'p1TotalRunningTime', 'p1TotalCuttingTime') AND deviceName = 'OKUMA.MachiningCenter.MU6300' ORDER BY timestamp DESC"
}
I get this result which I expect
Samples.AccumulatedTime.@@data|Samples.AccumulatedTime.name| deviceName | timestamp
------------------------------+----------------------------+----------------------------+------------------------
3949148 |p1TotalCuttingTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:22.255Z
45546100 |p1TotalRunningTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:22.243Z
4973127 |p1TotalOperatingTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:22.229Z
3949146 |p1TotalCuttingTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:20.069Z
45546098 |p1TotalRunningTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:20.043Z
4973125 |p1TotalOperatingTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:20.033Z
3949143 |p1TotalCuttingTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:17.506Z
45546095 |p1TotalRunningTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:17.496Z
4973122 |p1TotalOperatingTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:17.485Z
3949141 |p1TotalCuttingTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:15.259Z
45546092 |p1TotalRunningTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:15.233Z
4973120 |p1TotalOperatingTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:15.222Z
So I figure I would do a TOP 1
to get the top result of each in my list
POST /_sql?format=txt
{
"query": "SELECT TOP 1 \"Samples.AccumulatedTime.@@data\",\"Samples.AccumulatedTime.name\",deviceName,timestamp FROM \"mtconnect-demo\" WHERE \"Samples.AccumulatedTime.name\" IN ('p1TotalOperatingTime', 'p1TotalRunningTime', 'p1TotalCuttingTime') AND deviceName = 'OKUMA.MachiningCenter.MU6300' ORDER BY timestamp DESC"
}
But that will return just a single line of
Samples.AccumulatedTime.@@data|Samples.AccumulatedTime.name| deviceName | timestamp
------------------------------+----------------------------+----------------------------+------------------------
3949148 |p1TotalCuttingTime |OKUMA.MachiningCenter.MU6300|2022-03-03T17:32:22.255Z
And not the 3 items in my IN
list
How can I get the TOP 1
of each row of
p1TotalOperatingTime, p1TotalRunningTime, p1TotalCuttingTime
?