Solved

Sum the values from 2 different queries in 1 query

Posted on 2013-06-13
2
456 Views
Last Modified: 2013-06-13
Hi Experts

I have the 2 queries below, each of which gives me one number.  I want to be able to create a query which uses these 2 queries as subqueries so the 2 values can be summed and I have one total.  Can you help?

SELECT Sum([Pnl by GL - Accounting result].[SumOf7 Total Pnl YTD]) AS GL_ACCOUNTING
FROM [Pnl by GL - Accounting result]
WHERE ((([Pnl by GL - Accounting result].ReportCategory)="HTM" Or ([Pnl by GL - Accounting result].ReportCategory)="Loans&Receivables") AND (([Pnl by GL - Accounting result].AcctArea)="BA_AMADEUS" Or ([Pnl by GL - Accounting result].AcctArea)="BA_TOP_UP" Or ([Pnl by GL - Accounting result].AcctArea)="BA_CDS_HDG" Or ([Pnl by GL - Accounting result].AcctArea)="HENDERSON") AND (([Pnl by GL - Accounting result].AccountCode)=5865000000));

and

SELECT Sum([PnL by GL - Interest].[SumOf11 TotalInterest]) AS GL_INTEREST
FROM [PnL by GL - Interest]
WHERE ((([PnL by GL - Interest].ReportCategory)="Loans&Receivables" Or ([PnL by GL - Interest].ReportCategory)="HTM") AND (([PnL by GL - Interest].AcctArea)="BA_AMADEUS" Or ([PnL by GL - Interest].AcctArea)="BA_TOP_UP" Or ([PnL by GL - Interest].AcctArea)="BA_CDS_HDG" Or ([PnL by GL - Interest].AcctArea)="HENDERSON"));
0
Comment
Question by:simsima_7876
2 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 360 total points
ID: 39244083
Select q1.GL_ACCOUNTING+q2.GL_INTEREST as Mytotal from

(SELECT Sum([Pnl by GL - Accounting result].[SumOf7 Total Pnl YTD]) AS GL_ACCOUNTING
FROM [Pnl by GL - Accounting result]
WHERE ((([Pnl by GL - Accounting result].ReportCategory)="HTM" Or ([Pnl by GL - Accounting result].ReportCategory)="Loans&Receivables") AND (([Pnl by GL - Accounting result].AcctArea)="BA_AMADEUS" Or ([Pnl by GL - Accounting result].AcctArea)="BA_TOP_UP" Or ([Pnl by GL - Accounting result].AcctArea)="BA_CDS_HDG" Or ([Pnl by GL - Accounting result].AcctArea)="HENDERSON") AND (([Pnl by GL - Accounting result].AccountCode)=5865000000))) as q1,

(SELECT Sum([PnL by GL - Interest].[SumOf11 TotalInterest]) AS GL_INTEREST
FROM [PnL by GL - Interest]
WHERE ((([PnL by GL - Interest].ReportCategory)="Loans&Receivables" Or ([PnL by GL - Interest].ReportCategory)="HTM") AND (([PnL by GL - Interest].AcctArea)="BA_AMADEUS" Or ([PnL by GL - Interest].AcctArea)="BA_TOP_UP" Or ([PnL by GL - Interest].AcctArea)="BA_CDS_HDG" Or ([PnL by GL - Interest].AcctArea)="HENDERSON"))) as q2
0
 

Author Closing Comment

by:simsima_7876
ID: 39244092
Thanks very much.  Super quick!
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question