?
Solved

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

Posted on 2013-11-10
6
Medium Priority
?
351 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 1000 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 1000 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

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.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…
Suggested Courses

752 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