I have some data that looks like this:
my_table
| name | start | end |
|---|---|---|
| Michigan | 06-NOV-20 08.25.59.000000000 AM | 06-NOV-20 08.44.52.000000000 AM |
| State | 22-NOV-20 11.49.11.000000000 AM | 22-NOV-20 11.54.06.000000000 AM |
I'm trying to create a new column to calculate the duration as the difference between start and end. I then want to apply a mathematical average (mean/median) to find the average duration by year.
My code, currently:
SELECT
start - end AS duration
FROM
my_table
Current output:
| duration |
|---|
| -0 0:18:53.0 |
| -0 0:4:55.0 |
What I want:
| duration |
|---|
| 1133 |
| 295 |
How can I go about converting the duration field from datetime to seconds or minutes, so that I can apply an average function to the duration field?