Subject | Re: [firebird-support] SQL Optimation best way |
---|---|
Author | Ann Harrison |
Post date | 2015-11-04T20:09:47Z |
On Wed, Nov 4, 2015 at 8:41 AM, 'checkmail' check_mail@... [firebird-support] <firebird-support@yahoogroups.com> wrote:
two tables
A:
Field1, Field2, Field3, Field4, Field5
B
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 = condition2UNIONselect sum (b.fieldc) from B inner join Awhere A.field1 = condition1and A.field2 = condition2and B.fielda = A.field4and B.fieldb = A.field5If A.field3 and B.fieldc are of different types you may need to cast them.Good luck,Ann