AVG(date_column) overflow
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


AVG(date_column) overflow Expand / Collapse
Author
Message
Posted 6/9/2008 3:08:55 PM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 8/25/2008 5:46:43 PM
Posts: 23, Visits: 73
when I am trying to use the average funtion on a date field, please see the following sql.

select avg(planting_dt) from tablename;

I encountered following error message:

2616: Numeric overflow occurred during computation.

Is there any possible way to do average on a date filed which has a lot of values.

thanks,


Ivy
Post #11775
Posted 6/11/2008 12:30:15 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 6/11/2008 5:44:44 PM
Posts: 2, Visits: 9
wht i can understand is u may require to calculate most recurring date or the mid value of extreme dates.simple function of average wont wrk as two dates can not b added as its only DAYS tht can be added to a date.
for most recurring date use :
SELECT DATE_A
FROM
(
SELECT DATE_A,COUNT(*) AS COUNT_1
FROM TEMP
GROUP BY 1
) TAB_1 (DATE_A,COUNT_1)
QUALIFY RANK(COUNT_1 DESC) = 1
for mid value calc use :
select min(date_a) + ((max(date_a) - min(date_a))/2) from temp

Post #11805
Posted 6/11/2008 3:22:53 PM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 8/25/2008 5:46:43 PM
Posts: 23, Visits: 73
Thanks for the reply. We worked around this problem. Since all the dates are in one year, I convert it to Julian Date (YYYYDDD) first, then do a average on the last three digit. then convert it back to normal calendar date.
However, if our data set is across years, then I dont know how to deal with it.


Ivy
Post #11807
Posted 6/12/2008 10:02:36 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 6/27/2008 7:19:28 AM
Posts: 42, Visits: 54
You could use CALENDAR view :

SELECT cal.calendar_date AS avg_date
FROM sys_calendar.calendar AS cal
INNER JOIN
( SELECT AVG(cal.day_of_calendar) AS avg_day
FROM sys_calendar.calendar AS cal
INNER JOIN
tablename AS tbl
ON tbl.planting_dt = cal.calendar_date
) AS tmp
ON tmp.avg_day = cal.day_of_calendar
;
Post #11821
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 11:02am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.063. 9 queries. Compression Disabled.