[AccessD] SQL: Sum from the third table

Stuart McLachlan stuart at lexacorp.com.pg
Thu Jul 24 01:34:57 CDT 2003


On 24 Jul 2003 at 7:54, Ervin Brindza wrote:

>   Hope I don't want something impossible :)
>   Maybe someone on the List have a good idea...

Try this (Note I've change Order to Orders to aviod using a reserved word 
as a table name):

SELECT Q1.CustID, CustName,UKKol,UKVRed
FROM 
(SELECT CustName, CustID, Sum(Quantity) AS UKKol
FROM Customer 
    INNER JOIN Orders ON Customer.CustID = Orders.CustID
    INNER JOIN OrderDet ON Orders.REDBROJ = OrderDet.Redbroj
GROUP BY CustName, CustID) as Q1

 INNER JOIN

(SELECT  CustID, Sum(ValAmount) AS UKVRed
FROM Customer 
   INNER JOIN Orders ON Customer.CustID = Orders.CustID
GROUP BY CustName, CustID) as Q2

     ON Q1.CustID = Q2.CustID


-- 
Stuart McLachlan
Lexacorp Ltd
Application Development,  IT Consultancy
http://www.lexacorp.com.pg



More information about the AccessD mailing list