🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.interbase.sql
15 messages
15 total messages Started by Isaac Tue, 27 May 2008 19:59
can I use sum with computed by
#71
Author: Isaac
Date: Tue, 27 May 2008 19:59
8 lines
1069 bytes
Hello,
I wonder if I can use computed by to sum all detail records or is it 
only limited to the current table ?.

ex
select sum(f) from table where f2 = value

Thanks
Re: can I use sum with computed by
#72
Author: Bill Todd [TeamB]
Date: Tue, 27 May 2008 20:08
15 lines
1234 bytes
Isaac wrote:

> I wonder if I can use computed by to sum all detail records or is it
> only limited to the current table ?.

I do not understand what you mean by "computed by".

> 
> ex
> select sum(f) from table where f2 = value

That will work.

-- 
Bill Todd (TeamB)
Re: can I use sum with computed by
#73
Author: Isaac
Date: Tue, 27 May 2008 20:33
3 lines
1040 bytes
in the create table field definition "computed by" can I use the select 
statement ?
Re: can I use sum with computed by
#74
Author: Isaac
Date: Tue, 27 May 2008 20:44
14 lines
1328 bytes
CREATE TABLE table [EXTERNAL [FILE] 'filespec']
(col_def [, col_def | tconstraint �]);
col_def = col {datatype | COMPUTED [BY] (expr) | domain}
[DEFAULT {literal | NULL | USER}]
[NOT NULL]
[col_constraint]
[COLLATE collation]
.
.
.
.
.

P.S: How newsgroup support bold or italics ?
Re: can I use sum with computed by
#76
Author: willr
Date: Tue, 27 May 2008 20:53
21 lines
1485 bytes
Isaac wrote:
> CREATE TABLE table [EXTERNAL [FILE] 'filespec']
> (col_def [, col_def | tconstraint …]);
> col_def = col {datatype | COMPUTED [BY] (expr) | domain}
> [DEFAULT {literal | NULL | USER}]
> [NOT NULL]
> [col_constraint]
> [COLLATE collation]
> .
> .
> .
> .
> .
> 
> P.S: How newsgroup support bold or italics ?

_bold_ or /italics/?

-- 
Will R
PMC Consulting
Re: can I use sum with computed by
#75
Author: willr
Date: Tue, 27 May 2008 20:53
25 lines
1604 bytes
willr wrote:
> Isaac wrote:
>> CREATE TABLE table [EXTERNAL [FILE] 'filespec']
>> (col_def [, col_def | tconstraint …]);
>> col_def = col {datatype | COMPUTED [BY] (expr) | domain}
>> [DEFAULT {literal | NULL | USER}]
>> [NOT NULL]
>> [col_constraint]
>> [COLLATE collation]
>> .
>> .
>> .
>> .
>> .
>>
>> P.S: How newsgroup support bold or italics ?
> 
> _bold_ or /italics/?
> 

or maybe *bold* i dunno

-- 
Will R
PMC Consulting
Re: can I use sum with computed by
#77
Author: Bill Todd [TeamB]
Date: Tue, 27 May 2008 21:11
9 lines
1279 bytes
Isaac wrote:

> in the create table field definition "computed by" can I use the
> select statement ?

Yes, you can use a computed field in a SELECT statement.

-- 
Bill Todd (TeamB)
Re: can I use sum with computed by
#79
Author: Isaac
Date: Tue, 27 May 2008 21:20
12 lines
1378 bytes
Bill Todd [TeamB] wrote:
> Isaac wrote:
> 
>> in the create table field definition "computed by" can I use the
>> select statement ?
> 
> Yes, you can use a computed field in a SELECT statement.
> 
sorry I was not quit clear I want the contrary I want to use select 
sum() to return the computed by value

*Thanks*
Re: can I use sum with computed by
#78
Author: Isaac
Date: Tue, 27 May 2008 21:20
2 lines
1138 bytes
_*Thanks*_
Re: can I use sum with computed by
#81
Author: Bill Todd [TeamB]
Date: Tue, 27 May 2008 23:04
11 lines
1546 bytes
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.

-- 
Bill Todd (TeamB)
Re: can I use sum with computed by
#80
Author: 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
Re: can I use sum with computed by
#82
Author: Bill Todd [TeamB]
Date: Tue, 27 May 2008 23:42
9 lines
1376 bytes
Isaac wrote:

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

It should be because you only have to scan the data once.

-- 
Bill Todd (TeamB)
Re: can I use sum with computed by
#84
Author: Isaac
Date: Wed, 28 May 2008 10:06
1 lines
1160 bytes
Ok thanks alot
Re: can I use sum with computed by
#96
Author: Maxim Shiryaev
Date: Thu, 29 May 2008 14:16
23 lines
1473 bytes
Hi.

You can but it will be very inefficeint.

It's better to create triggers on detail table and update regular (not
computed) fields in the master. De-normalisation though...

Calculated fields will be better only if you have very strange read/write
ratio (in favour of write) for a usage senario of your database.


Maxim.

"Isaac" <no@no.com> ???????/???????? ? ???????? ?????????:
news:483c6824@newsgroups.borland.com...
> Hello,
> I wonder if I can use computed by to sum all detail records or is it
> only limited to the current table ?.
>
> ex
> select sum(f) from table where f2 = value
>
> Thanks
Re: can I use sum with computed by
#100
Author: Isaac
Date: Fri, 30 May 2008 15:06
15 lines
1339 bytes
Maxim Shiryaev wrote:
> Hi.
> 
> You can but it will be very inefficeint.
> 
> It's better to create triggers on detail table and update regular (not
> computed) fields in the master. De-normalisation though...
> 
> Calculated fields will be better only if you have very strange read/write
> ratio (in favour of write) for a usage senario of your database.
> 
> 
> Maxim.

ok thanks alot
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads