0

I am having a Table contain two columns named Time_stamp and PWPH_Pmp_2_FBSts and table name is per_hour_log The Sample of A Screen Shot I embedded

enter image description here

for the reference.The Query Which I Wrote is as follows

SELECT MAX(time_stamp) AS recent_datetime
FROM per_hour_log
WHERE PWPH_Pmp_2_FBSts = 2
AND time_stamp BETWEEN '2023-02-01 01:00:00' AND '2023-02-05 20:00:00'
AND EXISTS (
  SELECT 1 FROM per_hour_log
  WHERE PWPH_Pmp_2_FBSts = 1
  AND time_stamp BETWEEN '2023-02-01 01:00:00' AND '2023-02-05 20:00:00'
)

The OutPut I am Expecting is

03-02-2023  05:00:00
02-02-2023  13:00:00 
  • Don't really understand what do you want, but you can look into [lead()](https://learn.microsoft.com/en-us/sql/t-sql/functions/lead-transact-sql?view=sql-server-ver16) and [lag()](https://learn.microsoft.com/en-us/sql/t-sql/functions/lag-transact-sql?view=sql-server-ver16) – Squirrel Apr 02 '23 at 04:41
  • I Want write a query which will return me the value of timestamp where PWPH_Pmp_2_FBSts value changed from 1 to 2 like in attached image 03-02-2023 05:00:00 is the time stamp where tag value changed from 1 to 2 – LALIT ACHAREKAR Apr 02 '23 at 04:54

0 Answers0