Jump to content

Adding totals from multiple queries


Guest Kyri

Recommended Posts

I have two tables as per belowCust_TableCustnamePcode1Pcode2Pcode_TablePcodeIdValueThe Pcode is the master product id Pcode1 and Pcode2 are equal to the PcodeI use this to obtain the name and value from both tables.

SELECT Custname, Id, Value FROM Cust_Table,Pcode_Table WHERE Pcode1 = Pcode AND Custname= 'Bob' Union All SELECT Custname, Id, Value FROM Cust_Table,Pcode_Table WHERE Pcode2 = Pcode AND Custname= 'Bob'

This returns for exampleCustname................Id................ValueBob.........................Brush...........5Bob.........................Table...........8I want to be able to produce the above result but to also include the total value of the items in the case above 13Hope someone can help

Link to comment
Share on other sites

Hi.. add the following query in your query. "Union All select sum(value) from Cust_Table,Pcode_Table WHERE Pcode2 = Pcode AND Custname= 'Bob' "QUERY:=SELECT Custname, Id, Value FROM Cust_Table,Pcode_Table WHERE Pcode1 = Pcode AND Custname= 'Bob'Union All SELECT Custname, Id, Value FROM Cust_Table,Pcode_Table WHERE Pcode2 = Pcode AND Custname= 'Bob' Union All select sum(value) from Cust_Table,Pcode_Table WHERE Pcode2 = Pcode AND Custname= 'Bob' Regards,Vijay

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...