Article View: borland.public.interbase.sql
Article #68Re: can I do that with one select statement
From: Maxim Shiryaev
Date: Tue, 27 May 2008 12:01
Date: Tue, 27 May 2008 12:01
40 lines
1801 bytes
1801 bytes
Hi. Try: for select field_a, sum(field_b) from t group by field_a into :v_a, :v_sum_b do begin if (v_a) = 1 then some_var_1 = v_sum_b; else if (v_a) = 2 then some_var_2 = v_sum_b; /* and more if's if ther are more distinct values in field_a */ end Maxim. "Isaac" <no@no.com> ???????/???????? ? ???????? ?????????: news:483bca8e@newsgroups.borland.com... > Hello, > I need to to sum a field and store the result into a variable in a > stored procedure, can I use one select statement to get the sum based on > a condition from another field > > ex > sum(field_a) when field_b = 1 > sum(field_a) when field_b = 0 > > field_a field_b > 5 1 > 10 0 > 52 1 > > > or I have to use two select ? sorry this may appear stupid but I am > asking to improve performance > > Thanks
Technical Details
Message-ID:
<483bf82c@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<483bca8e@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,e4861ce108d51b43 X-Google-Attributes: gid114a0e,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Maxim Shiryaev" <MaximShiryaev@gmail.com> Newsgroups: borland.public.interbase.sql References: <483bca8e@newsgroups.borland.com> Subject: Re: can I do that with one select statement Date: Tue, 27 May 2008 16:01:24 +0400 Lines: 42 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 213.234.197.62 Message-ID: <483bf82c@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1211889708 213.234.197.62 (27 May 2008 05:01:48 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail