Subject Re: [firebird-support] SQL Optimation best way
Author Ann Harrison
On Wed, Nov 4, 2015 at 8:41 AM, 'checkmail' check_mail@... [firebird-support] <> wrote:

 two tables



Field1, Field2, Field3, Field4, Field5



FieldA,  FieldB, FieldC


Now I would like to get the following:


Sum(A.field3) where a.field1 = condition1 and a.field2 = condition2

In the same statement I would include

Sum(b.fieldc) where b.fielda = a.field4 and b.fieldb = a.field5


Without having tried it, I suggest:

select sum (A.field3) from A where A.field1 = condition1 and A.field2 = condition2
select sum (b.fieldc) from B inner join A
         where  A.field1 = condition1 
                    and A.field2 = condition2 
                    and B.fielda = A.field4
                    and B.fieldb = A.field5

If A.field3 and B.fieldc are of different types you may need to cast them.

Good luck,