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  

aggregate



 
 
Thread Tools Display Modes
  #1  
Old October 19th, 2004, 04:01 PM
Brenda @ AIM
external usenet poster
 
Posts: n/a
Default aggregate

I used the COUNT function in a query to count the number of fields. I gave
it the name COUNTOF.
Now I want to make a query from that query and I try to select COUNTOF and I
get an error message telling me that I tried to execute a query the doesn't
include COUNTOF as part of an aggregate function.
Why can't I just select it as a field name in the second query?
  #2  
Old October 19th, 2004, 04:29 PM
Lynn Trapp
external usenet poster
 
Posts: n/a
Default

Could you post the SQL for your queries?

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


"Brenda @ AIM" wrote in message
...
I used the COUNT function in a query to count the number of fields. I

gave
it the name COUNTOF.
Now I want to make a query from that query and I try to select COUNTOF and

I
get an error message telling me that I tried to execute a query the

doesn't
include COUNTOF as part of an aggregate function.
Why can't I just select it as a field name in the second query?



  #3  
Old October 19th, 2004, 04:32 PM
Jamie Richards
external usenet poster
 
Posts: n/a
Default

Hi Brenda,

I don't suppose you could post your SQL? Did you say you are counting
fields? Did you mean rows (records)?

Any time you use an aggregate function in a query you must "group" the
non-aggregated fields. Lets say you had 3 fields in your query:

[Order Period], [Product Name] and [Quantity Ordered]. [Quantity Ordered]
is the aggregated field. You would structure the SQL something like this:

--NB: This SQL not tested

SELECT Format(OrderDate, "YYYY/MM") AS [Order Period],
ProductName AS Product,
COUNT(*) AS [Quantity Ordered]
FROM ((Orders AS O INNER JOIN [Order Details] AS OD ON O.OrderID =
OD.OrderID)
INNER JOIN Products P ON OD.ProductID = P.ProductID)
GROUP BY Format(OrderDate, "YYYY/MM") , ProductName

The number of rows are counted for each change in Period and Product Name.
Do not include the alias names (i.e. [Order Period], etc) in the GROUP BY
clause.

Jamie

"Brenda @ AIM" wrote in message
...
I used the COUNT function in a query to count the number of fields. I gave
it the name COUNTOF.
Now I want to make a query from that query and I try to select COUNTOF and
I
get an error message telling me that I tried to execute a query the
doesn't
include COUNTOF as part of an aggregate function.
Why can't I just select it as a field name in the second query?



  #4  
Old October 19th, 2004, 04:59 PM
Brenda @ AIM
external usenet poster
 
Posts: n/a
Default

This is my first query
SELECT LEFT(ZIP,5) AS UNIZIP, COUNT(ZIPCODES.ZIP) AS COUNTOFZIP
FROM ZIPCODES
GROUP BY LEFT(ZIP,5);

This is the query I'm getting the error message on.
SELECT LEFT(UNIZIP,3) AS ZIP3, COUNTOFZIP
FROM QRYUNIQUEZIP
WHERE UNIZIP NOT IN
(SELECT UNIZIP
FROM QRYUNIQUEZIP
WHERE COUNTOFZIP 15
GROUP BY UNIZIP)
GROUP BY LEFT(UNIZIP,3)
UNION ALL
SELECT UNIZIP, COUNTOFZIP
FROM QRYUNIQUEZIP
WHERE COUNTOFZIP 15
GROUP BY UNIZIP;



"Lynn Trapp" wrote:

Could you post the SQL for your queries?

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


"Brenda @ AIM" wrote in message
...
I used the COUNT function in a query to count the number of fields. I

gave
it the name COUNTOF.
Now I want to make a query from that query and I try to select COUNTOF and

I
get an error message telling me that I tried to execute a query the

doesn't
include COUNTOF as part of an aggregate function.
Why can't I just select it as a field name in the second query?




  #5  
Old October 19th, 2004, 04:59 PM
Brenda @ AIM
external usenet poster
 
Posts: n/a
Default

This is my first query:
SELECT LEFT(ZIP,5) AS UNIZIP, COUNT(ZIPCODES.ZIP) AS COUNTOFZIP
FROM ZIPCODES
GROUP BY LEFT(ZIP,5);
Here is the query I'm getting the error message on:
SELECT LEFT(UNIZIP,3) AS ZIP3, COUNTOFZIP
FROM QRYUNIQUEZIP
WHERE UNIZIP NOT IN
(SELECT UNIZIP
FROM QRYUNIQUEZIP
WHERE COUNTOFZIP 15
GROUP BY UNIZIP)
GROUP BY LEFT(UNIZIP,3)
UNION ALL
SELECT UNIZIP, COUNTOFZIP
FROM QRYUNIQUEZIP
WHERE COUNTOFZIP 15
GROUP BY UNIZIP;

"Jamie Richards" wrote:

Hi Brenda,

I don't suppose you could post your SQL? Did you say you are counting
fields? Did you mean rows (records)?

Any time you use an aggregate function in a query you must "group" the
non-aggregated fields. Lets say you had 3 fields in your query:

[Order Period], [Product Name] and [Quantity Ordered]. [Quantity Ordered]
is the aggregated field. You would structure the SQL something like this:

--NB: This SQL not tested

SELECT Format(OrderDate, "YYYY/MM") AS [Order Period],
ProductName AS Product,
COUNT(*) AS [Quantity Ordered]
FROM ((Orders AS O INNER JOIN [Order Details] AS OD ON O.OrderID =
OD.OrderID)
INNER JOIN Products P ON OD.ProductID = P.ProductID)
GROUP BY Format(OrderDate, "YYYY/MM") , ProductName

The number of rows are counted for each change in Period and Product Name.
Do not include the alias names (i.e. [Order Period], etc) in the GROUP BY
clause.

Jamie

"Brenda @ AIM" wrote in message
...
I used the COUNT function in a query to count the number of fields. I gave
it the name COUNTOF.
Now I want to make a query from that query and I try to select COUNTOF and
I
get an error message telling me that I tried to execute a query the
doesn't
include COUNTOF as part of an aggregate function.
Why can't I just select it as a field name in the second query?




  #6  
Old October 19th, 2004, 05:21 PM
Brenda @ AIM
external usenet poster
 
Posts: n/a
Default

I realize now that I need to put COUNTOFZIP in my GROUPBY clause. But if I
write it like this (GROUP BY UNIZIP, COUNTOFZIP) then I have multiple
instances of my UNIZIP in the result. I need these grouped together. If i
write it this way (GROUP BY COUNTOFZIP, UNIZIP) then it is grouped by the
count(ascending). I need it grouped by UNIZIP (ascending)

"Brenda @ AIM" wrote:

This is my first query
SELECT LEFT(ZIP,5) AS UNIZIP, COUNT(ZIPCODES.ZIP) AS COUNTOFZIP
FROM ZIPCODES
GROUP BY LEFT(ZIP,5);

This is the query I'm getting the error message on.
SELECT LEFT(UNIZIP,3) AS ZIP3, COUNTOFZIP
FROM QRYUNIQUEZIP
WHERE UNIZIP NOT IN
(SELECT UNIZIP
FROM QRYUNIQUEZIP
WHERE COUNTOFZIP 15
GROUP BY UNIZIP)
GROUP BY LEFT(UNIZIP,3)
UNION ALL
SELECT UNIZIP, COUNTOFZIP
FROM QRYUNIQUEZIP
WHERE COUNTOFZIP 15
GROUP BY UNIZIP;



"Lynn Trapp" wrote:

Could you post the SQL for your queries?

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


"Brenda @ AIM" wrote in message
...
I used the COUNT function in a query to count the number of fields. I

gave
it the name COUNTOF.
Now I want to make a query from that query and I try to select COUNTOF and

I
get an error message telling me that I tried to execute a query the

doesn't
include COUNTOF as part of an aggregate function.
Why can't I just select it as a field name in the second query?




  #7  
Old October 19th, 2004, 05:41 PM
Lynn Trapp
external usenet poster
 
Posts: n/a
Default

Get it to be in the order you want by using an Order By clause at the end of
the second query.

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


"Brenda @ AIM" wrote in message
...
I realize now that I need to put COUNTOFZIP in my GROUPBY clause. But if

I
write it like this (GROUP BY UNIZIP, COUNTOFZIP) then I have multiple
instances of my UNIZIP in the result. I need these grouped together. If

i
write it this way (GROUP BY COUNTOFZIP, UNIZIP) then it is grouped by the
count(ascending). I need it grouped by UNIZIP (ascending)

"Brenda @ AIM" wrote:

This is my first query
SELECT LEFT(ZIP,5) AS UNIZIP, COUNT(ZIPCODES.ZIP) AS COUNTOFZIP
FROM ZIPCODES
GROUP BY LEFT(ZIP,5);

This is the query I'm getting the error message on.
SELECT LEFT(UNIZIP,3) AS ZIP3, COUNTOFZIP
FROM QRYUNIQUEZIP
WHERE UNIZIP NOT IN
(SELECT UNIZIP
FROM QRYUNIQUEZIP
WHERE COUNTOFZIP 15
GROUP BY UNIZIP)
GROUP BY LEFT(UNIZIP,3)
UNION ALL
SELECT UNIZIP, COUNTOFZIP
FROM QRYUNIQUEZIP
WHERE COUNTOFZIP 15
GROUP BY UNIZIP;



"Lynn Trapp" wrote:

Could you post the SQL for your queries?

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


"Brenda @ AIM" wrote in message
...
I used the COUNT function in a query to count the number of fields.

I
gave
it the name COUNTOF.
Now I want to make a query from that query and I try to select

COUNTOF and
I
get an error message telling me that I tried to execute a query the
doesn't
include COUNTOF as part of an aggregate function.
Why can't I just select it as a field name in the second query?





 




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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Aggregate Queries hassles Richard Hollenbeck Running & Setting Up Queries 7 October 8th, 2004 09:04 PM
How do i get an aggregate product? sofere Running & Setting Up Queries 1 September 15th, 2004 01:00 AM
Create Aggregate Function Marshall Smith Running & Setting Up Queries 1 August 4th, 2004 11:55 AM
filter adp report where record source uses aggregate functions eddiec Running & Setting Up Queries 3 July 12th, 2004 07:48 AM
Aggregate function to sort of report Drew Setting Up & Running Reports 5 May 27th, 2004 09:36 PM


All times are GMT +1. The time now is 03:23 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.