How to calculate average time in SQL Big Query? [duplicate] - sql

This question already has answers here:
How to calculate average time when it is used TIME format in Bigquery?
(3 answers)
SQL AVG Function with with a time format
(1 answer)
Closed 5 months ago.
I want to find out average time on SQL Big Query. I tried using the CAST function but it's not working.
For example-
Ride_length
01:01:00
00:58:00
01:14:00
00:34:00
01:03:00
00:34:00
00:40:00
01:00:00
there are 5451210 rows in ride_length column.
Date type = TIME
Please help!

Related

Number of Days in a month HIVE [duplicate]

This question already has answers here:
Find last day of a month in Hive
(6 answers)
Closed 1 year ago.
Can someone let me know a simple way to get # of days in a month in HIVE SQL based on current_date.
e.g. 2021-02-16 = 28 days, 2021-06-30 = 30 days etc
Use
day(last_day(current_date))
last_day(date) returns last day date, day(date) returns day part of the date, int
See manual here: Language Manual - Date Functions

Postgresql: round up the time to nearest 15 minute range (0,15,30,45) [duplicate]

This question already has answers here:
postgresql date_trunc to arbitrary precision?
(3 answers)
How to round to nearest X minutes with PL/pgSQL?
(8 answers)
What is the fastest way to truncate timestamps to 5 minutes in Postgres?
(4 answers)
Postgresql round timestamp to nearest 30 seconds
(3 answers)
Closed 3 years ago.
From this post's answer, I have a datetime column where I do date_time::timestamp - INTERVAL '1 HOUR' in the select statement.
What I want to do is that, I want to create a interval of a 15 minutes range (0, 15,30,45) So, the result should be like 2019-04-21 09:00:00 or 2019-04-21 09:15:00 and so on. The result should be change to the nearest time i.e. for 00:00 to 07:29 minute will be round down to 00:00 and 07:30 to 15:00 will be round up to 15:00.This apply to 15, 30 and 45 as well
So from 2019-04-21 09:52:29 should become 2019-04-21 09:45:00 and 2019-04-21 09:52:30 should become 2019-04-21 10:00:00
I have searched and found date_trunc function but I don't know how to do base on what I specific.
Thank you!
Edit: I have look at the duplicated post and some answers. I found answer that used dateadd and datediff function but these functions cannot be use with postgresql.
select dateadd(minute, datediff(minute,0,GETDATE()) / 15 * 15, 0)
How can apply this to postgresql ?
Edit2: There are solutions that use a create function to round up and down but the above is quite better.

Get the date with 0 as time [duplicate]

This question already has answers here:
how to remove time from datetime
(10 answers)
What is the best way to truncate a date in SQL Server?
(6 answers)
Closed 8 years ago.
I'm using the following query to get the maximum days in a month as a datetime.
Select DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,'2014-01-01')+1,0))
The query result is: 2014-01-31 23:59:59.000
How can I get the following result : 2014-01-31 00:00:00.000
Thanks,

Compare a datetime field within 2 hours [duplicate]

This question already has answers here:
SQL: Get records created in time range for specific dates
(3 answers)
Closed 8 years ago.
I have a table with the field ENTERED_ON (with both date and time value). I want to write a query that return records that have ENTERED_ON value that is past 2 hours comparing to current date time.
For example, if entered_on is 2014-05-06 11:00AM, and currently it's 2014-05-06 2:00PM, I would like to return all records that past the 2 hours when comparing to current date time.
You can write query using INTERVAL. It will looks like
SELECT * FROM Table WHERE `ENTERED_ON` > DATE_ADD(NOW(), INTERVAL -2 HOUR)

SQL last month date of given date [duplicate]

This question already has answers here:
Get the last day of the month in SQL
(22 answers)
Closed 9 years ago.
i am using sql
How to get the last day of the month for a given date
01/03/2014 should return 01/31/2014
I only need the date part.. Thanks
For SQL-SERVER, try this:
SELECT convert(varchar,(DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,'01/03/2014 ')+1,0))),101)