Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread SQL ?
Thu, May 18 2006 10:33 AMPermanent Link

"Uffe Kousgaard"
I have this SQL:

select field1, sum(field2*field3) "Newfield1", sum(field2+field3)
"Newfield2"
from ....
group by field1

How do I also get included in the output newfield1/newfield2*100 as another
field ? And even better casted as an integer.

DBISAM 3.30

Regards
Uffe

Thu, May 18 2006 1:48 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Uffe


I'm not sure you can in V3, but in V4

select _boxtype, sum(_boxno * _belongsto) "Newfield1", sum(_boxno + _belongsto) "Newfield2",
CAST ((sum(_boxno * _belongsto) / sum((_boxno + _belongsto) * 100)) AS INTEGER) "Newfield3"
from banda
group by _boxtype;

works. If it doesn't for you try a script, do your first select into a memory table and then work on the fields from there


Roy Lambert
Thu, May 18 2006 2:18 PMPermanent Link

"Robert"

"Uffe Kousgaard" <oh@no.no> wrote in message
news:F8222136-CF4B-4A00-BFD2-43B00DE233B3@news.elevatesoft.com...
>I have this SQL:
>
> select field1, sum(field2*field3) "Newfield1", sum(field2+field3)
> "Newfield2"
> from ....
> group by field1
>
> How do I also get included in the output newfield1/newfield2*100 as
> another field ? And even better casted as an integer.
>
> DBISAM 3.30
>

I think if you use parenthesis to indicate the sequence of operations

SUM (((Field2*Field3) / (Field4 + Field5)) * 100)

should give you the result you want. You can wrap the whole thing in a
"cast" if necessary.

Robert

Mon, May 22 2006 8:26 AMPermanent Link

"Uffe Kousgaard"
"Roy Lambert" <roy.lambert@skynet.co.uk> wrote in message
news:34F5B608-FF89-458B-8B6A-AA01CF1925FB@news.elevatesoft.com...
>
> works. If it doesn't for you try a script, do your first select into a
> memory table and then work on the fields from there

Thanks, that's what I ended up doing.

Image