All Forums Database
aarsh.dave 24 posts Joined 11/12
26 Mar 2014
Getting average using inbuilt Teradata functions

HI,
I have a table that stores a timestamp field, START_TM.
What I want to do is find average number of records on this table for the past one month.
I wrote the following query and it works.
SELECT
count(*) / (select (count (distinct start_tm)) from DB_NAME.TBL_NM
where trunc(start_ts) >= (current_date-30) ) as Averag
FROM DB_NAME.TBL_NM trunc(start_ts) >= (current_date-30)
 
However, I was wondering if there is an easy way to get the desired result using any inbuilt teradata functions like average.
 
Please let me know if there is.
Thanks,
Aarsh

Adharssh 36 posts Joined 08/13
02 Apr 2014

Hi Aarsh,
There is a inbuilt function called 'AVG', which will do the average function.

SELECT
AVG(start_tm) from DB_NAME.TBL_NM
where trunc(start_ts) >= (current_date-30) ) as Averag
FROM DB_NAME.TBL_NM trunc(start_ts) >= (current_date-30)

Thanks & Regards,
Adharssh.

Share the Knowledge. Feel the Happiness, When you share/Teach it.

You must sign in to leave a comment.