Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Group By does not return right result with multiple tabl
Message
 
 
To
18/01/2007 20:29:28
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01186807
Message ID:
01186913
Views:
21
>>And every record in Trans may or may not have records in payments or charges.
>
>Then make those both left joins instead of inner joins, and use nvl()... like this:
>
>
>Select Trans.cTrans_fk, Sum(nvl(Payments.yAmount_paid,0)) as yAmount_paid, ;
>   Sum(nvl(Charges.yCharges_amount,0)) as yCharges_amount ;
>   from Trans ;
>   left join Payments ;
>      on Trans.cTrans_pk = Payments.cTrans_fk ;
>   left join Charges ;
>      on Trans.cTrans_pk = Charges.cTrans_fk ;
>   group by 1
>
>With inner joins you see only transactions where you have records in all three tables for a given transaction.

I believe it's a solution to the problem except that you probably need to put 0000000000.00 (as many 0 as the final field should be).

UPDATE. But it turned out I was wrong and the query doesn't work correctly.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform