1

I have a query where I need it to only return results where an event occurs more than once on the same date on the same model/serial number - in this query, whenever the specific function and eventdetails parameters occur more than once in one day. Here is the query -

SELECT DISTINCT store, tintermodel, tinterserial, eventdetails, trunc(datetime)
FROM tinter_events
WHERE tintermodel = 'FM 8000DE'  
AND (datetime >= to_timestamp('2017-05-01', 'YYYY-MM-DD') 
AND datetime < to_timestamp('2017-08-31', 'YYYY-MM-DD'))
AND function = 'Set Colorant Level'
AND eventdetails = 'B1[550]'
GROUP BY store, tintermodel, tinterserial, eventdetails, trunc(datetime)
ORDER BY store, SUBSTR(eventdetails,1,2), trunc(datetime);

Would it be as simple as adding a HAVING COUNT(*) > 1 at the end of the GROUP BY phrase?

2
  • What happened when you tried it? Commented Sep 13, 2017 at 17:43
  • My problem is I'm not sure if that's returning what I want (the query takes a good 15 minutes to run each time. Commented Sep 13, 2017 at 17:53

1 Answer 1

1

Check it by looking at the counts per date per model, from there you would know which records should only show on your query

SELECT trunc(datetime),
       tintermodel,
       COUNT(*)
  FROM tinter_events
 WHERE tintermodel = 'FM 8000DE'
   AND function = 'Set Colorant Level'
   AND eventdetails = 'B1[550]
 GROUP BY trunc(datetime),
          tintermodel
 ORDER BY trunc(datetime)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - a slightly edited version of that worked for what I need!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.