Solved

Simple SQL (why does it take me 2 queries when 1 should suffice?)

Posted on 2013-11-10
6
347 Views
Last Modified: 2013-11-10
See attached.

I want a query on the SalesInvoices table with the following characteristics;

1. Only include data from 2012
2. Use "group by" to produce the following format;

Joe     425
Tom   406


This should be fairly easy.  However, can it be done in a SINGLE query.  I find I need 2 queries.
TwoQueries.accdb
0
Comment
Question by:Patrick O'Dea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 39637511
try this query

SELECT SalesInvoices.Salesman, SalesInvoices.Year, Sum(SalesInvoices.InvoiceValue) AS SumOfInvoiceValue
FROM SalesInvoices
GROUP BY SalesInvoices.Salesman, SalesInvoices.Year
HAVING (((SalesInvoices.Year)="2012"));
0
 
LVL 12

Accepted Solution

by:
duttcom earned 250 total points
ID: 39637515
Set up the query like this -
Single queryThis returns the results you are after.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39637523
if you want only two columns in a single query, use this query


Select A.Salesman,A.SumOfInvoiceValue
From
(
SELECT SalesInvoices.Salesman, SalesInvoices.Year, Sum(SalesInvoices.InvoiceValue) AS SumOfInvoiceValue
FROM SalesInvoices
GROUP BY SalesInvoices.Salesman, SalesInvoices.Year
HAVING (((SalesInvoices.Year)="2012"))
) As A
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Expert Comment

by:enfworks
ID: 39637524
SELECT SalesInvoices.Salesman, Sum(SalesInvoices.InvoiceValue) AS SumOfInvoiceValue
FROM SalesInvoices
WHERE (((SalesInvoices.year)='2012'))
GROUP BY SalesInvoices.Salesman;
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39637527
or this query


SELECT SalesInvoices.Salesman, Sum(SalesInvoices.InvoiceValue) AS SumOfInvoiceValue
FROM SalesInvoices
GROUP BY SalesInvoices.Salesman, SalesInvoices.Year
HAVING (((SalesInvoices.Year)="2012"));
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 39637529
Thanks folks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

717 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