szadroga
asked on
SQL code to determine the time between to timestamps
I have the following query which is working fine, but i need to determine the "time" between the min_event_timestamp and max_event_timestamp as a new field.
SELECT
events.event_log.user_id,
events.event.name AS event_name,
MIN(events.event_log.times tamp) As min_event_timestamp,
MAX(events.event_log.times tamp) AS max_event_timestamp,
FROM
events.event
INNER JOIN
events.event_log
ON
(
events.event.id = events.event_log.event_id)
WHERE
events.event_log.event_id IN (4)
GROUP BY event_log.user_id, event.name;
SELECT
events.event_log.user_id,
events.event.name AS event_name,
MIN(events.event_log.times
MAX(events.event_log.times
FROM
events.event
INNER JOIN
events.event_log
ON
(
events.event.id = events.event_log.event_id)
WHERE
events.event_log.event_id IN (4)
GROUP BY event_log.user_id, event.name;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
was using a different db type than i stated so i provided the solution i used
If so, try this (considering that you want the result in seconds (s), otherwise you can alter the datepart value in DATEDIFF function:
Open in new window