I am getting the following rows when I perform this query:
SELECT *
FROM statetable
where "machineName" ='Main01'
ORDER BY statetable_ndx DESC LIMIT 100
machineName | state | stateDuratio | t_stamp |
---|---|---|---|
Main01 | 3 | 12002 | 2023-06-29 21:21:04.152 |
Main01 | 5 | 360169 | 2023-06-29 21:20:58.144 |
Main01 | 3 | 3002 | 2023-06-29 21:20:34.013 |
Main01 | 5 | 45024 | 2023-06-29 21:20:18.983 |
Main01 | 4 | 18007 | 2023-06-29 21:20:12.972 |
... and so on...
Now my question is, I am trying to query to get the highest 3 top values from the stateDuration column. So far this is what I have tried, and it's now sorting by the highest 3 sorted out by StateDuration..
SELECT "State",
"StateName",
Max("StateDuration") as "StateDuration"
FROM statetable
where "machineName" ='Main01'
Group by "State", "StateName"
ORDER BY "StateDuration" DESC
LIMIT 100;
However, the problem for me is when I try to also filter by a time frame:
when I try to add a timeframe line (like this line in the following query: AND t_stamp >= '2023-08-10 16:30:00' AND t_stamp <= '2023-08-14 00:30:00') I don't get any result and I don't understand why. Does someone has any clue for me?
SELECT "State","StateName",
Max("StateDuration") as "StateDuration"
FROM statetable
where "machineName" ='Main01'
AND t_stamp >= '2023-08-10 16:30:00' AND t_stamp <= '2023-08-14 00:30:00'
Group by "State", "StateName"
ORDER BY "StateDuration" DESC
LIMIT 100;