-1

I have a table in oracle user_transn(userid, resourceid, transid, act_timestamp) with values like

    (21, 14, 123321, 28-NOV-11 13:30:21)
    (21, 14, 123321, 28-NOV-11 14:29:28)
    (21, 14, 123321, 29-NOV-11 18:44:22)
    (21, 14, 123321, 30-NOV-11 11:30:55)
    (21, 14, 123321, 30-NOV-11 16:56:11)
    (21, 14, 123321, 30-NOV-11 19:32:31)
    (21, 14, 123321, 31-NOV-11 09:22:51)
    (21, 14, 123321, 31-NOV-11 12:22:49)
    (21, 14, 123321, 31-NOV-11 13:11:17)
    (21, 14, 123321, 31-NOV-11 16:41:21)

The query should take the minimum time of the act_timestamp field of each distinct date and calculate the average minimum time over the given date range (which in this case is 28-31 nov)

So for above the result should be: 13:30:21 + 11:30:55 + 9:22:51 /3 = 11:27:42 as the average min time

and similarly for max time.

Thanks in advance

4
  • Why do you ignore 29-NOV-11 18:44:22 ?
    – Peter Lang
    Apr 13, 2012 at 9:33
  • 1
    Also, which calendar allows 31 days in November?
    – Peter Lang
    Apr 13, 2012 at 9:38
  • And your example is wrong. The average of your three values is 11:28:02, not 11:27:42.
    – Peter Lang
    Apr 13, 2012 at 9:58
  • What have you attempted when trying to solve your problem?
    – Ben
    Apr 13, 2012 at 10:16

1 Answer 1

1

Select min_timestamp, calculate the average of the time-part, and add the current day to convert back to a date:

SELECT
  TO_CHAR(TRUNC(SYSDATE) + AVG(min_timestamp - TRUNC(min_timestamp)), 'HH24:MI:SS')
FROM
(
  SELECT MIN(act_timestamp) AS min_timestamp
  FROM user_transn
  GROUP BY TRUNC(act_timestamp)
)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.