A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Adding up row values



 
 
Thread Tools Display Modes
  #1  
Old March 15th, 2010, 10:47 PM posted to microsoft.public.access.queries
kthomas
external usenet poster
 
Posts: 7
Default Adding up row values

I am trying to add up all "fertilizer" costs by customer name. However, I am
getting 3 results per customer due to there being 3 types of fertilizer. How
can I combine into one customer, one fertilizer total sales? Code below.

SELECT [SL Customers].[Customer Name], [SL Inventory].[Item Description],
Sum([qty]*[unit price]) AS Total
FROM (([SL Customers] RIGHT JOIN [SL Invoices] ON [SL Customers].[Customer
Number] = [SL Invoices].[Customer Number]) RIGHT JOIN [SL Items Sold] ON [SL
Invoices].[SOP Number] = [SL Items Sold].[SOP Number]) LEFT JOIN [SL
Inventory] ON [SL Items Sold].[Item Number] = [SL Inventory].[Item Number]
GROUP BY [SL Customers].[Customer Name], [SL Inventory].[Item Description]
HAVING ((([SL Inventory].[Item Description]) Like "*fertilizer*"))
ORDER BY Sum([qty]*[unit price]) DESC;

  #2  
Old March 15th, 2010, 11:12 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Adding up row values

How can I combine into one customer, one fertilizer total sales?
Drop [SL Inventory].[Item Description] from the query.

SELECT [SL Customers].[Customer Name], Sum([qty]*[unit price]) AS Total
FROM (([SL Customers] RIGHT JOIN [SL Invoices] ON [SL Customers].[Customer
Number] = [SL Invoices].[Customer Number]) RIGHT JOIN [SL Items Sold] ON [SL
Invoices].[SOP Number] = [SL Items Sold].[SOP Number]) LEFT JOIN [SL
Inventory] ON [SL Items Sold].[Item Number] = [SL Inventory].[Item Number]
GROUP BY [SL Customers].[Customer Name]
HAVING ((([SL Inventory].[Item Description]) Like "*fertilizer*"))
ORDER BY Sum([qty]*[unit price]) DESC;

--
Build a little, test a little.


"kthomas" wrote:

I am trying to add up all "fertilizer" costs by customer name. However, I am
getting 3 results per customer due to there being 3 types of fertilizer. How
can I combine into one customer, one fertilizer total sales? Code below.

SELECT [SL Customers].[Customer Name], [SL Inventory].[Item Description],
Sum([qty]*[unit price]) AS Total
FROM (([SL Customers] RIGHT JOIN [SL Invoices] ON [SL Customers].[Customer
Number] = [SL Invoices].[Customer Number]) RIGHT JOIN [SL Items Sold] ON [SL
Invoices].[SOP Number] = [SL Items Sold].[SOP Number]) LEFT JOIN [SL
Inventory] ON [SL Items Sold].[Item Number] = [SL Inventory].[Item Number]
GROUP BY [SL Customers].[Customer Name], [SL Inventory].[Item Description]
HAVING ((([SL Inventory].[Item Description]) Like "*fertilizer*"))
ORDER BY Sum([qty]*[unit price]) DESC;

  #3  
Old March 15th, 2010, 11:16 PM posted to microsoft.public.access.queries
kthomas
external usenet poster
 
Posts: 7
Default Adding up row values

But that brings in all items purchased by customer when I only need
fertilizer items by customer?

"KARL DEWEY" wrote:

How can I combine into one customer, one fertilizer total sales?

Drop [SL Inventory].[Item Description] from the query.

SELECT [SL Customers].[Customer Name], Sum([qty]*[unit price]) AS Total
FROM (([SL Customers] RIGHT JOIN [SL Invoices] ON [SL Customers].[Customer
Number] = [SL Invoices].[Customer Number]) RIGHT JOIN [SL Items Sold] ON [SL
Invoices].[SOP Number] = [SL Items Sold].[SOP Number]) LEFT JOIN [SL
Inventory] ON [SL Items Sold].[Item Number] = [SL Inventory].[Item Number]
GROUP BY [SL Customers].[Customer Name]
HAVING ((([SL Inventory].[Item Description]) Like "*fertilizer*"))
ORDER BY Sum([qty]*[unit price]) DESC;

--
Build a little, test a little.


"kthomas" wrote:

I am trying to add up all "fertilizer" costs by customer name. However, I am
getting 3 results per customer due to there being 3 types of fertilizer. How
can I combine into one customer, one fertilizer total sales? Code below.

SELECT [SL Customers].[Customer Name], [SL Inventory].[Item Description],
Sum([qty]*[unit price]) AS Total
FROM (([SL Customers] RIGHT JOIN [SL Invoices] ON [SL Customers].[Customer
Number] = [SL Invoices].[Customer Number]) RIGHT JOIN [SL Items Sold] ON [SL
Invoices].[SOP Number] = [SL Items Sold].[SOP Number]) LEFT JOIN [SL
Inventory] ON [SL Items Sold].[Item Number] = [SL Inventory].[Item Number]
GROUP BY [SL Customers].[Customer Name], [SL Inventory].[Item Description]
HAVING ((([SL Inventory].[Item Description]) Like "*fertilizer*"))
ORDER BY Sum([qty]*[unit price]) DESC;

  #4  
Old March 15th, 2010, 11:18 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Adding up row values

kthomas wrote:

I am trying to add up all "fertilizer" costs by customer name. However, I am
getting 3 results per customer due to there being 3 types of fertilizer. How
can I combine into one customer, one fertilizer total sales? Code below.

SELECT [SL Customers].[Customer Name], [SL Inventory].[Item Description],
Sum([qty]*[unit price]) AS Total
FROM (([SL Customers] RIGHT JOIN [SL Invoices] ON [SL Customers].[Customer
Number] = [SL Invoices].[Customer Number]) RIGHT JOIN [SL Items Sold] ON [SL
Invoices].[SOP Number] = [SL Items Sold].[SOP Number]) LEFT JOIN [SL
Inventory] ON [SL Items Sold].[Item Number] = [SL Inventory].[Item Number]
GROUP BY [SL Customers].[Customer Name], [SL Inventory].[Item Description]
HAVING ((([SL Inventory].[Item Description]) Like "*fertilizer*"))
ORDER BY Sum([qty]*[unit price]) DESC;



You need to remove the item description field from the
Select and Group By clauses.

You also should change the Having clause to a Where clause.

--
Marsh
MVP [MS Access]
  #5  
Old March 16th, 2010, 02:00 AM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Adding up row values

On Mon, 15 Mar 2010 15:47:01 -0700, kthomas
wrote:

I am trying to add up all "fertilizer" costs by customer name. However, I am
getting 3 results per customer due to there being 3 types of fertilizer. How
can I combine into one customer, one fertilizer total sales? Code below.

SELECT [SL Customers].[Customer Name], [SL Inventory].[Item Description],
Sum([qty]*[unit price]) AS Total
FROM (([SL Customers] RIGHT JOIN [SL Invoices] ON [SL Customers].[Customer
Number] = [SL Invoices].[Customer Number]) RIGHT JOIN [SL Items Sold] ON [SL
Invoices].[SOP Number] = [SL Items Sold].[SOP Number]) LEFT JOIN [SL
Inventory] ON [SL Items Sold].[Item Number] = [SL Inventory].[Item Number]
GROUP BY [SL Customers].[Customer Name], [SL Inventory].[Item Description]
HAVING ((([SL Inventory].[Item Description]) Like "*fertilizer*"))
ORDER BY Sum([qty]*[unit price]) DESC;


Change the HAVING to WHERE (which applies before the grouping is done) and
remove Item Description from the GROUP BY clause.

To do this in the query grid change the Totals row under Item Description from
the default Group BY to Where (Access will uncheck the Show checkbox).
--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:08 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.