Getting average using inbuilt Teradata functions

Database

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

1 REPLY

Re: Getting average using inbuilt Teradata functions

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.