Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Group By does not return right result with multiple tabl
Message
 
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:
01186922
Views:
28
>I changed your sample using GROUP BY, works fine. But I added one more insert
>to second cursor (INSERT INTO crsTest2 VALUES (1,100)) and now I get wrong value for Total Amount2 (first record)
>
>
>CREATE CURSOR crsTest  (Fld1 I)
>CREATE CURSOR crsTest1 (Fld1 I, amount n)
>CREATE CURSOR crsTest2 (Fld1 I, amount n)
>
>INSERT INTO crsTest VALUES (1)
>INSERT INTO crsTest VALUES (2)
>INSERT INTO crsTest VALUES (3)
>
>INSERT INTO crsTest1 VALUES (1,10)
>INSERT INTO crsTest1 VALUES (1,10)
>INSERT INTO crsTest1 VALUES (3,30)
>INSERT INTO crsTest1 VALUES (3,30)
>
>INSERT INTO crsTest2 VALUES (2,20)
>INSERT INTO crsTest2 VALUES (2,20)
>INSERT INTO crsTest2 VALUES (1,100)
>
>SELECT crsTest.Fld1, SUM(crsTest1.Amount) as Amount1, ;
>SUM(crsTest2.Amount) as Amount2;
>FROM crsTest;
>INNER JOIN crsTest1 ON crsTest.Fld1 = crsTest1.Fld1;
>INNER JOIN crsTest2 ON crsTest.Fld1 = crsTest2.Fld1;
>GROUP BY 1
>
>** (no records in the query)
>SELECT crsTest.Fld1, SUM(NVL(crsTest1.Amount,0)) as Amount1, SUM(NVL(crsTest2.Amount,0)) as Amount2;
>FROM crsTest;
>LEFT JOIN crsTest1 ON crsTest.Fld1 = crsTest1.Fld1;
>LEFT JOIN crsTest2 ON crsTest.Fld1 = crsTest2.Fld1;
>GROUP BY 1
>
You're right, it doesn't work correctly for some reason.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform