How to do?

How to do?

Post by Javier Palme » Tue, 08 Sep 1998 04:00:00



I've 4 tables

TABLE A_Master
-------------------------
IdA

TABLE A_Detail
------------------------
IdA
Units

TABLE B_Master
--------------------------
IdB
IdA

TABLE B_Detail
------------------------
IdB
Units

AND, I need to select then rows of A  where the sum of items of A
(A_Detail.Unit) are diferent of all the sum of items of B (B_Detail.Unit)
that are linked to A (B_Master.IdA = A_Master.IdA)

I do

SELECT  MA.IdA, SUM(DA.Items),SUM(DB.Items)
FROM            Master_A MA
                JOIN Detail_A   DA ON DA.IdA = MA.Ida
                JOIN Master_B MB ON MB.Ida = MA.IdA
                JOIN Detail_B   DB ON DB.IdB = MB.IdB
GROUP BY MA.IdA
HAVING SUM(DA.Items)<>SUM(DB.Items)

but don't work, It return bad results

Please, help....

 
 
 

How to do?

Post by Vladimir Tumano » Wed, 09 Sep 1998 04:00:00


SELECT MA.IdA, SUM(DA.Items)
FROM     Master_A MA
     JOIN   Detail_A   DA   ON DA.IdA = MA.IdA
GROUP BY MA.IdA
HAVING NOT EXISTS ( SELECT MB.IdB, SUM(DB.Items)
                                          FROM     Master_B MB
                                               JOIN   Detail_B   DB   ON
DB.IdB = MB.IdB
                                          WHERE  MB.IdA = MA.IdA
                                          GROUP BY MB.IdB
                                          HAVING  SUM(DA.Items) =
SUM(DB.Items)
                                        )

Vladimir Tumanov
Novosibirsk, Russia

--------------------------------------------------------------

Quote:>I've 4 tables

>TABLE A_Master
>-------------------------
>IdA

>TABLE A_Detail
>------------------------
>IdA
>Units

>TABLE B_Master
>--------------------------
>IdB
>IdA

>TABLE B_Detail
>------------------------
>IdB
>Units

>AND, I need to select then rows of A  where the sum of items of A
>(A_Detail.Unit) are diferent of all the sum of items of B (B_Detail.Unit)
>that are linked to A (B_Master.IdA = A_Master.IdA)

>I do

>SELECT MA.IdA, SUM(DA.Items),SUM(DB.Items)
>FROM Master_A MA
> JOIN Detail_A   DA ON DA.IdA = MA.Ida
> JOIN Master_B MB ON MB.Ida = MA.IdA
> JOIN Detail_B   DB ON DB.IdB = MB.IdB
>GROUP BY MA.IdA
>HAVING SUM(DA.Items)<>SUM(DB.Items)

>but don't work, It return bad results

>Please, help....


 
 
 

1. ADO thinks DBMS is done, but DBMS ain't done

I have 2 Recordsets on 2 different applications communicating with the same
database

-=The first Recordset is opened with=-
m_pGlobal_RS->Open(adCmd, m_pConnection.GetInterfacePtr(), adOpenKeyset,
adLockPessimistic, adCmdText);

-=The second Recordset is opened with=-
local_RS->Open(adCmd, m_pConnection.GetInterfacePtr(), adOpenKeyset,
adLockReadOnly, adCmdText);

* adCmd is a simple SELECT statement that is the SAME for both recordsets.

The code order is roughly this

Open m_pGlobal_RS
...
...
Change fields on m_pGlobal_RS
...
...
MoveNext on all rows of m_pGlobal_RS until EOF then MoveFirst  // since
pessimistic every row op sends update
..
..
I then fire an event to another application which opens local_RS.

It is random whether the data opened by the second RS is the pre-update data
or the post-update data. How can this be? I opened the connection
with the default  synchronous option, isn't this asynchronous behavior?

Thanks for the help,
-=Adog

2. Database Integrity

3. Trigger doing UNLOAD to file OR calling Store Procedure doing the UNLOAD to file

4. Analyze in Oracle 8.0.5

5. Caché from InterSystems - doing wh at other MV vendors should be doing

6. What is meant by "Ad Hoc" querry?

7. Is this doing what I think it's doing?

8. SQL Puzzle: trying to get rows in grouped query even if they have no data

9. Are We Doing A Deal Or Are We Doing A Deal ?

10. ASP - OLEDB Provider done yet login problem exsists

11. problem doing a restore

12. spaces in column names, when doing sql calls in java

13. Can this be done in one statement?