0
user_id raisedtime cleartime duration
3_dsr 2022-07-22 2022-07-23 20
3_dsr 2022-07-22 2022-07-24 22
1_DSR 2022-07-24 2022-07-26 21
1_DSR 2022-07-24 2022-07-26 21

I tried this and cant get further with this

select user_id,raisedtime, max(duration) as md 
from alarms 
group by user_id,raisedtime 
having count(*)>1   
Adriaan
  • 17,741
  • 7
  • 42
  • 75
rizah
  • 1
  • 1
  • 1
    MySQL and Oracle are two different RDBMS; which one are you using? – MT0 Jul 25 '22 at 09:24
  • Show desired output for this data. – Akina Jul 25 '22 at 09:24
  • ```.. HAVING MAX(duration) > MIN(duration)``` ? – Akina Jul 25 '22 at 09:26
  • 1
    Please do not change code, error messages or other text to images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](https://meta.stackoverflow.com/a/285557). Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. See [mcve] on what code is required. – Adriaan Jul 25 '22 at 09:27
  • *than the previous duplicate value* What is "previous"? with what ordering? – Akina Jul 25 '22 at 09:27

1 Answers1

0

NOTE You need to extract the table with below query and identify max duration using python pandas. IN SQL you will only get this far. Also, using Max(duration) will give you row with MAXIMUM duration but it cannot guarantee, it will check if it MAX from previous occurrence of user_id and raisedtime pair.

SELECT user_id, raisedtime, duration as md
FROM alarms 
GROUP BY user_id, raisedtime 
HAVING count(*)>1  

You can use python pandas library to identify MAX for pair of unique user_id and raisetime pair and check if that occurrence is greater than earlier occurrence of same pair.

DataFramed
  • 1,491
  • 16
  • 21