🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #80

Re: can I use sum with computed by

#80
From: Isaac
Date: Tue, 27 May 2008 23:08
33 lines
2021 bytes
Bill Todd [TeamB] wrote:
> Isaac wrote:
> 
>> sorry I was not quit clear I want the contrary I want to use select
>> sum() to return the computed by value
> 
> I do not recall if that  will work or not but it is a very bad idea.
> The SELECT SUM will run _every_ time the record is accessed whether you
> need the sume or not. This is likely to cause poor performance.
> 
ok speaking of performance Mr Maxim tell me a good way to get two sum 
values with for select ...

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


is this better in performance (for a stored procedure) than using 2 Selects

ex:

select sum(f) from tab1 where f2 = 1

Thanks
select sum(f) from tab1 where f2 = 0
Technical Details
Message-ID: <483c9479@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <483c6824@newsgroups.borland.com> <483c6a5b@newsgroups.borland.com> <483c700d$1@newsgroups.borland.com> <483c78e5$1@newsgroups.borland.com> <483c7b10@newsgroups.borland.com> <483c937b$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,f81bba07595296f5
X-Google-Attributes: gid114a0e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 28 May 2008 02:08:29 +0300
From: Isaac <no@no.com>
User-Agent: Thunderbird 2.0.0.14 (Windows/20080421)
MIME-Version: 1.0
Newsgroups: borland.public.interbase.sql
Subject: Re: can I use sum with computed by
References: <483c6824@newsgroups.borland.com> <483c6a5b@newsgroups.borland.com> <483c700d$1@newsgroups.borland.com> <483c78e5$1@newsgroups.borland.com> <483c7b10@newsgroups.borland.com> <483c937b$1@newsgroups.borland.com>
In-Reply-To: <483c937b$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 41.234.198.147
Message-ID: <483c9479@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1211929721 41.234.198.147 (27 May 2008 16:08:41 -0700)
Lines: 33
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail