Article View: borland.public.interbase.sql
Article #540Re: Extract use
From: dan palley
Date: Tue, 20 Nov 2007 18:11
Date: Tue, 20 Nov 2007 18:11
29 lines
2051 bytes
2051 bytes
"Zoren Lendry" <zorenlendry@yahoo.com> wrote in message news:4742788d$1@newsgroups.borland.com... > �������� ����������� wrote: >> Can you tell me how i use the Extract in a Date Field? >> I want to sum by a month. Please write an example > > select EXTRACT(month from TRAN_DATE), sum(GRAND_TOTAL) > from TRAN_TABLE > where TRAN_DATE >= '1/1/2005' > group by EXTRACT(month from TRAN_DATE) > > but this is bad, because it adds all Januaries together (unless, of > course, this is what you want; you might want to see which month does > better!). So, to make it like I think you want it, simply change it as > follows: > > select EXTRACT(year from TRAN_DATE), EXTRACT(month from TRAN_DATE), > sum(GRAND_TOTAL) > from SALES_TRAN > where TRAN_DATE >= '1/1/2005' > group by EXTRACT(year from TRAN_DATE), EXTRACT(month from TRAN_DATE) Won't work in IB, unfortunately -- cannot GROUP BY anything other than a column (this is an interbase newsgroup, after all). You could write 12 separate selects (one for each month) and combine them using UNION. Dan
Technical Details
Message-ID:
<4743235d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.germany.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<47427718@newsgroups.borland.com> <4742788d$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,ba5f46b06493ddc2 X-Google-Attributes: gid114a0e,public,usenet X-Google-Language: ENGLISH,ASCII From: "dan palley" <dan@trams.com> Newsgroups: borland.public.interbase.sql References: <47427718@newsgroups.borland.com> <4742788d$1@newsgroups.borland.com> Subject: Re: Extract use Date: Tue, 20 Nov 2007 10:11:54 -0800 Lines: 31 Organization: TRAMS X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.3959 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 66.102.131.254 Message-ID: <4743235d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1195582301 66.102.131.254 (20 Nov 2007 10:11:41 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.germany.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail