Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 13 of 13 total
Thread Behaviour with DATES confusing me
Tue, Jul 26 2011 5:33 PMPermanent Link

Chris B

"John Hay" wrote:

>>To make this work you can use CAST eg

>>SELECT SaleDate - CAST(EXTRACT(DAYOFWEEK FROM SaleDate)-1 AS INTERVAL DAY) AS StartOfWeek
FROM Sale

Ha! Seems so obvious now.


>>Once you sort the syntax (cast) it works really well (automatically ignores the nulls) eg

>>SELECT DATE'1901-01-01' + CAST(AVG(TransactionDate - DATE'1901-01-01') AS INTERVAL DAY) AS AverageDate FROM Table

DATE'1901-01-01' + AVG(TransactionDate - DATE'1901-01-01') works in 2.05B3 without any casts.
Tue, Jul 26 2011 6:00 PMPermanent Link

John Hay

Chris

>
> DATE'1901-01-01' + AVG(TransactionDate - DATE'1901-01-01') works in 2.05B3 without any casts.
>

Maybe if I should read your post more carefully I could take my foot out of my mouth Smiley

John

Tue, Aug 9 2011 4:42 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Chris,

<< Anyway, the query for a date average that I wrote above actually works
fine ... I'm not sure why though ... AVG() appears to return an integer and
normally we're unable to add an integer to a date. >>

The query that you posted subtracts a date from a date, which will return a
DAY interval, by default.  The AVG() calculation is averaging days, not
normal integer values.   The two happen to be the same thing in this case,
but that's just a coincidence due to the unit of measure being used.

--
Tim Young
Elevate Software
www.elevatesoft.com
« Previous PagePage 2 of 2
Jump to Page:  1 2
Image