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  

Sumarize data in Query like in a Pivot Table



 
 
Thread Tools Display Modes
  #1  
Old December 3rd, 2009, 07:09 PM posted to microsoft.public.access.queries
excelCPA
external usenet poster
 
Posts: 18
Default Sumarize data in Query like in a Pivot Table

I have a query that pulls in data from payroll and sales tables.
Results are similar to the following:

Payroll_No L_Name Sale_No Sale_Amt
12345 Smith 2434 100
12345 Smith 3434 200
12345 Smith 3654 50
23456 Jones 7870 50
23456 Jones 7987 200
45678 Phillips 2223 100
45678 Phillips 9898 50
45678 Phillips 9896 300
45678 Phillips 7878 200
45678 Phillips 8989 400

The SQL is:

SELECT tblPerson.Payroll_No, tblPerson.L_Name, tblSale.Sale_No,
tblSale.Sale_Amt
FROM tblSale INNER JOIN tblPerson ON tblSale.Payroll_No = tblPerson.
Payroll_No

I need to make the query summarize the data per payroll number by
count, sum, and average similar to a Pivot Table. The results for the
data above would look like this:

Payroll_No L_Name Count_Sale_No Sum_Sale_Amt Avg_Sale_Amt
12345 Smith 3
350 116.67
23456 Jones 2
250 175
45678 Phillips 5
1050 2100

How can this be accomplished? Thanks.
  #2  
Old December 3rd, 2009, 08:58 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Sumarize data in Query like in a Pivot Table

It is called a 'Totals' query.
Open your query in design view and click on the icon that looks like an 'M'
on its side - ∑ - and then change the GROUP BYs to the math function you want
to use.

--
Build a little, test a little.


"excelCPA" wrote:

I have a query that pulls in data from payroll and sales tables.
Results are similar to the following:

Payroll_No L_Name Sale_No Sale_Amt
12345 Smith 2434 100
12345 Smith 3434 200
12345 Smith 3654 50
23456 Jones 7870 50
23456 Jones 7987 200
45678 Phillips 2223 100
45678 Phillips 9898 50
45678 Phillips 9896 300
45678 Phillips 7878 200
45678 Phillips 8989 400

The SQL is:

SELECT tblPerson.Payroll_No, tblPerson.L_Name, tblSale.Sale_No,
tblSale.Sale_Amt
FROM tblSale INNER JOIN tblPerson ON tblSale.Payroll_No = tblPerson.
Payroll_No

I need to make the query summarize the data per payroll number by
count, sum, and average similar to a Pivot Table. The results for the
data above would look like this:

Payroll_No L_Name Count_Sale_No Sum_Sale_Amt Avg_Sale_Amt
12345 Smith 3
350 116.67
23456 Jones 2
250 175
45678 Phillips 5
1050 2100

How can this be accomplished? Thanks.
.

  #3  
Old December 3rd, 2009, 10:49 PM posted to microsoft.public.access.queries
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Sumarize data in Query like in a Pivot Table

You can also do it by a modest amendment to the existing SQL:

SELECT tblPerson.Payroll_No, tblPerson.L_Name,
COUNT(*) AS Count_Sale_No,
SUM(tblSale.Sale_Amt) AS Sum_Sale_Amt,
AVG(tblSale.Sale_Amt) AS Avg_Sale_Amt
FROM tblSale INNER JOIN tblPerson
ON tblSale.Payroll_No = tblPerson.Payroll_No
GROUP BY tblPerson.Payroll_No, tblPerson.L_Name;

Ken Sheridan
Stafford, England

excelCPA wrote:
I have a query that pulls in data from payroll and sales tables.
Results are similar to the following:

Payroll_No L_Name Sale_No Sale_Amt
12345 Smith 2434 100
12345 Smith 3434 200
12345 Smith 3654 50
23456 Jones 7870 50
23456 Jones 7987 200
45678 Phillips 2223 100
45678 Phillips 9898 50
45678 Phillips 9896 300
45678 Phillips 7878 200
45678 Phillips 8989 400

The SQL is:

SELECT tblPerson.Payroll_No, tblPerson.L_Name, tblSale.Sale_No,
tblSale.Sale_Amt
FROM tblSale INNER JOIN tblPerson ON tblSale.Payroll_No = tblPerson.
Payroll_No

I need to make the query summarize the data per payroll number by
count, sum, and average similar to a Pivot Table. The results for the
data above would look like this:

Payroll_No L_Name Count_Sale_No Sum_Sale_Amt Avg_Sale_Amt
12345 Smith 3
350 116.67
23456 Jones 2
250 175
45678 Phillips 5
1050 2100

How can this be accomplished? Thanks.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200912/1

  #4  
Old December 4th, 2009, 01:52 PM posted to microsoft.public.access.queries
excelCPA
external usenet poster
 
Posts: 18
Default Sumarize data in Query like in a Pivot Table

On Dec 3, 5:49*pm, "KenSheridan via AccessMonster.com" u51882@uwe
wrote:
You can also do it by a modest amendment to the existing SQL:

SELECT tblPerson.Payroll_No, tblPerson.L_Name,
COUNT(*) AS Count_Sale_No,
SUM(tblSale.Sale_Amt) AS Sum_Sale_Amt,
AVG(tblSale.Sale_Amt) AS Avg_Sale_Amt
FROM tblSale INNER JOIN tblPerson
ON tblSale.Payroll_No = tblPerson.Payroll_No
GROUP BY tblPerson.Payroll_No, tblPerson.L_Name;

Ken Sheridan
Stafford, England





excelCPA wrote:
I have a query that pulls in data from payroll and sales tables.
Results are similar to the following:


Payroll_No * L_Name * *Sale_No * Sale_Amt
12345 * * * * * Smith * * * *2434 * * * * *100
12345 * * * * * Smith * * * *3434 * * * * *200
12345 * * * * * Smith * * * *3654 * * * * *50
23456 * * * * * Jones * * * *7870 * * * * * 50
23456 * * * * * Jones * * * *7987 * * * * *200
45678 * * * * * Phillips * * 2223 * * * * *100
45678 * * * * * Phillips * * 9898 * * * * * 50
45678 * * * * * Phillips * * 9896 * * * * *300
45678 * * * * * Phillips * * 7878 * * * * *200
45678 * * * * * Phillips * * 8989 * * * * *400


The SQL is:


SELECT tblPerson.Payroll_No, tblPerson.L_Name, tblSale.Sale_No,
tblSale.Sale_Amt
FROM tblSale INNER JOIN tblPerson ON tblSale.Payroll_No = tblPerson.
Payroll_No


I need to make the query summarize the data per payroll number by
count, sum, and average similar to a Pivot Table. *The results for the
data above would look like this:


Payroll_No *L_Name * Count_Sale_No *Sum_Sale_Amt *Avg_Sale_Amt
12345 * * * * * Smith * * * * * * * * *3
350 * * * * * * * * * * 116.67
23456 * * * * * Jones * * * * * * * * *2
250 * * * * * * * * * * 175
45678 * * * * * Phillips * * * * * * * *5
1050 * * * * * * * * * * 2100


How can this be accomplished? Thanks.


--
Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200912/1- Hide quoted text -

- Show quoted text -


Thanks, I tried this, but it is still all indivual Payroll_No's
instead of a single row for each. Any ideas?
  #5  
Old December 4th, 2009, 01:55 PM posted to microsoft.public.access.queries
excelCPA
external usenet poster
 
Posts: 18
Default Sumarize data in Query like in a Pivot Table

On Dec 3, 5:49*pm, "KenSheridan via AccessMonster.com" u51882@uwe
wrote:
You can also do it by a modest amendment to the existing SQL:

SELECT tblPerson.Payroll_No, tblPerson.L_Name,
COUNT(*) AS Count_Sale_No,
SUM(tblSale.Sale_Amt) AS Sum_Sale_Amt,
AVG(tblSale.Sale_Amt) AS Avg_Sale_Amt
FROM tblSale INNER JOIN tblPerson
ON tblSale.Payroll_No = tblPerson.Payroll_No
GROUP BY tblPerson.Payroll_No, tblPerson.L_Name;

Ken Sheridan
Stafford, England





excelCPA wrote:
I have a query that pulls in data from payroll and sales tables.
Results are similar to the following:


Payroll_No * L_Name * *Sale_No * Sale_Amt
12345 * * * * * Smith * * * *2434 * * * * *100
12345 * * * * * Smith * * * *3434 * * * * *200
12345 * * * * * Smith * * * *3654 * * * * *50
23456 * * * * * Jones * * * *7870 * * * * * 50
23456 * * * * * Jones * * * *7987 * * * * *200
45678 * * * * * Phillips * * 2223 * * * * *100
45678 * * * * * Phillips * * 9898 * * * * * 50
45678 * * * * * Phillips * * 9896 * * * * *300
45678 * * * * * Phillips * * 7878 * * * * *200
45678 * * * * * Phillips * * 8989 * * * * *400


The SQL is:


SELECT tblPerson.Payroll_No, tblPerson.L_Name, tblSale.Sale_No,
tblSale.Sale_Amt
FROM tblSale INNER JOIN tblPerson ON tblSale.Payroll_No = tblPerson.
Payroll_No


I need to make the query summarize the data per payroll number by
count, sum, and average similar to a Pivot Table. *The results for the
data above would look like this:


Payroll_No *L_Name * Count_Sale_No *Sum_Sale_Amt *Avg_Sale_Amt
12345 * * * * * Smith * * * * * * * * *3
350 * * * * * * * * * * 116.67
23456 * * * * * Jones * * * * * * * * *2
250 * * * * * * * * * * 175
45678 * * * * * Phillips * * * * * * * *5
1050 * * * * * * * * * * 2100


How can this be accomplished? Thanks.


--
Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200912/1- Hide quoted text -

- Show quoted text -


Also when use this SQL, I get a "Syntax error in GROUP BY clause"
  #6  
Old December 4th, 2009, 04:13 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Sumarize data in Query like in a Pivot Table

Try it this way --
SELECT tblPerson.Payroll_No, tblPerson.L_Name, COUNT(*) AS Count_Sale_No,
SUM(tblSale.Sale_Amt) AS Sum_Sale_Amt, AVG(tblSale.Sale_Amt) AS Avg_Sale_Amt
FROM tblPerson LEFT JOIN tblSale ON tblSale.Payroll_No = tblPerson.Payroll_No
GROUP BY tblPerson.Payroll_No, tblPerson.L_Name;

--
Build a little, test a little.


"excelCPA" wrote:

On Dec 3, 5:49 pm, "KenSheridan via AccessMonster.com" u51882@uwe
wrote:
You can also do it by a modest amendment to the existing SQL:

SELECT tblPerson.Payroll_No, tblPerson.L_Name,
COUNT(*) AS Count_Sale_No,
SUM(tblSale.Sale_Amt) AS Sum_Sale_Amt,
AVG(tblSale.Sale_Amt) AS Avg_Sale_Amt
FROM tblSale INNER JOIN tblPerson
ON tblSale.Payroll_No = tblPerson.Payroll_No
GROUP BY tblPerson.Payroll_No, tblPerson.L_Name;

Ken Sheridan
Stafford, England





excelCPA wrote:
I have a query that pulls in data from payroll and sales tables.
Results are similar to the following:


Payroll_No L_Name Sale_No Sale_Amt
12345 Smith 2434 100
12345 Smith 3434 200
12345 Smith 3654 50
23456 Jones 7870 50
23456 Jones 7987 200
45678 Phillips 2223 100
45678 Phillips 9898 50
45678 Phillips 9896 300
45678 Phillips 7878 200
45678 Phillips 8989 400


The SQL is:


SELECT tblPerson.Payroll_No, tblPerson.L_Name, tblSale.Sale_No,
tblSale.Sale_Amt
FROM tblSale INNER JOIN tblPerson ON tblSale.Payroll_No = tblPerson.
Payroll_No


I need to make the query summarize the data per payroll number by
count, sum, and average similar to a Pivot Table. The results for the
data above would look like this:


Payroll_No L_Name Count_Sale_No Sum_Sale_Amt Avg_Sale_Amt
12345 Smith 3
350 116.67
23456 Jones 2
250 175
45678 Phillips 5
1050 2100


How can this be accomplished? Thanks.


--
Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200912/1- Hide quoted text -

- Show quoted text -


Also when use this SQL, I get a "Syntax error in GROUP BY clause"
.

  #7  
Old December 4th, 2009, 05:48 PM posted to microsoft.public.access.queries
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Sumarize data in Query like in a Pivot Table

I can't spot any error in the SQL statement at first sight. Copy the SQL
statement exactly a you've used it when it raises the error, and post it back
here.

Ken Sheridan
Stafford, England

excelCPA wrote:
On Dec 3, 5:49 pm, "KenSheridan via AccessMonster.com" u51882@uwe
wrote:
You can also do it by a modest amendment to the existing SQL:

[quoted text clipped - 49 lines]

- Show quoted text -


Also when use this SQL, I get a "Syntax error in GROUP BY clause"


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200912/1

  #8  
Old December 4th, 2009, 06:55 PM posted to microsoft.public.access.queries
excelCPA
external usenet poster
 
Posts: 18
Default Sumarize data in Query like in a Pivot Table

I got it working. I forgot to select "Group By" instead of sum in the
desin view. Thanks for your help.



On Dec 4, 12:48*pm, "KenSheridan via AccessMonster.com" u51882@uwe
wrote:
I can't spot any error in the SQL statement at first sight. *Copy the SQL
statement exactly a you've used it when it raises the error, and post it back
here.

Ken Sheridan
Stafford, England

excelCPA wrote:
On Dec 3, 5:49 pm, "KenSheridan via AccessMonster.com" u51882@uwe
wrote:
You can also do it by a modest amendment to the existing SQL:


[quoted text clipped - 49 lines]


- Show quoted text -


Also when use this SQL, I get a "Syntax error in GROUP BY clause"


--
Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200912/1


 




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 11:41 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.