473,395 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Aggregate help

I am trying to count the total number of units for a given part number
that have a Priority rating of 1. Based upon some research, this is
what I came up with for my query. Access says that I have invalid
bracketing in the Select Distinct statement. The only brackets I
inserted were to delimit the table's field names. Access did the rest.
Also, Access created the second AS bracket group - [%$##@_Alias].

Am I barking up the right tree or is my query statement way off base?
I am not sure where to put the WHERE clause and I don't understand the
bracketing error Access is giving.

Query Statement:
SELECT COUNT(*) AS ["Planned Ships"] FROM [SELECT DISTINCT [Part No
2540] FROM RMAs WHERE [Priority] =1] AS [%$##@_Alias] GROUP BY [Part
No 2540];

Thanks in advance.

Troy Lee
Jun 27 '08 #1
6 1869
<tr******@comcast.netwrote in message
news:a5**********************************@26g2000h sk.googlegroups.com...
>I am trying to count the total number of units for a given part number
that have a Priority rating of 1. Based upon some research, this is
what I came up with for my query. Access says that I have invalid
bracketing in the Select Distinct statement. The only brackets I
inserted were to delimit the table's field names. Access did the rest.
Also, Access created the second AS bracket group - [%$##@_Alias].

Am I barking up the right tree or is my query statement way off base?
I am not sure where to put the WHERE clause and I don't understand the
bracketing error Access is giving.

Query Statement:
SELECT COUNT(*) AS ["Planned Ships"] FROM [SELECT DISTINCT [Part No
2540] FROM RMAs WHERE [Priority] =1] AS [%$##@_Alias] GROUP BY [Part
No 2540];

Thanks in advance.

Troy Lee
Try something like

Select Distinct Count(*) as "Planned Ships" from RMAs Where [Priority] =1
GROUP BY [PartNo 2540]

Keith.
www.keithwilby.com

Jun 27 '08 #2
tr******@comcast.net wrote:
I am trying to count the total number of units for a given part number
that have a Priority rating of 1. Based upon some research, this is
what I came up with for my query. Access says that I have invalid
bracketing in the Select Distinct statement. The only brackets I
inserted were to delimit the table's field names. Access did the rest.
Also, Access created the second AS bracket group - [%$##@_Alias].

Am I barking up the right tree or is my query statement way off base?
I am not sure where to put the WHERE clause and I don't understand the
bracketing error Access is giving.

Query Statement:
SELECT COUNT(*) AS ["Planned Ships"] FROM [SELECT DISTINCT [Part No
2540] FROM RMAs WHERE [Priority] =1] AS [%$##@_Alias] GROUP BY [Part
No 2540];

Thanks in advance.

Troy Lee
Select Count(*) As "Planned Ships" From RMAs WHere Priority = 1

If you're going to group by [Part No 2540], why don't you show it as a
column? It'd be kinda ridiculous to see a list of 1, 20, 12, 15 with no
idea what the value is of the field [Part No 2540] since you'll be
breaking on the different values of the [Part No 2540] field.

You might consider going thru help and reading to understand SQL, Totals
queries, Aggregate functions, where clauses, etc.

Or search Google for info. I entered Access Queries in google and came
up with http://www.fmsinc.com/tpapers/queries/ for a starter, lots more
available. You really should get a firm background on how to create a
query before designing one.

Wave Insanity
http://www.youtube.com/watch?v=8LoH6oQzJZs
Jun 27 '08 #3
On Jun 16, 10:58 am, Salad <o...@vinegar.comwrote:
troy_...@comcast.net wrote:
I am trying to count the total number of units for a given part number
that have a Priority rating of 1. Based upon some research, this is
what I came up with for my query. Access says that I have invalid
bracketing in the Select Distinct statement. The only brackets I
inserted were to delimit the table's field names. Access did the rest.
Also, Access created the second AS bracket group - [%$##@_Alias].
Am I barking up the right tree or is my query statement way off base?
I am not sure where to put the WHERE clause and I don't understand the
bracketing error Access is giving.
Query Statement:
SELECT COUNT(*) AS ["Planned Ships"] FROM [SELECT DISTINCT [Part No
2540] FROM RMAs WHERE [Priority] =1] AS [%$##@_Alias] GROUP BY [Part
No 2540];
Thanks in advance.
Troy Lee

Select Count(*) As "Planned Ships" From RMAs WHere Priority = 1

If you're going to group by [Part No 2540], why don't you show it as a
column? It'd be kinda ridiculous to see a list of 1, 20, 12, 15 with no
idea what the value is of the field [Part No 2540] since you'll be
breaking on the different values of the [Part No 2540] field.

You might consider going thru help and reading to understand SQL, Totals
queries, Aggregate functions, where clauses, etc.

Or search Google for info. I entered Access Queries in google and came
up withhttp://www.fmsinc.com/tpapers/queries/for a starter, lots more
available. You really should get a firm background on how to create a
query before designing one.

Wave Insanityhttp://www.youtube.com/watch?v=8LoH6oQzJZs
Access doesn't recognize the Count Distinct function, does it?
Everywhere I have been reading, it says that I have to use a subquery
to use the Distinct function. Is this not true?
Jun 27 '08 #4
tr******@comcast.net wrote:
On Jun 16, 10:58 am, Salad <o...@vinegar.comwrote:
>>troy_...@comcast.net wrote:
>>>I am trying to count the total number of units for a given part number
that have a Priority rating of 1. Based upon some research, this is
what I came up with for my query. Access says that I have invalid
bracketing in the Select Distinct statement. The only brackets I
inserted were to delimit the table's field names. Access did the rest.
Also, Access created the second AS bracket group - [%$##@_Alias].
>>>Am I barking up the right tree or is my query statement way off base?
I am not sure where to put the WHERE clause and I don't understand the
bracketing error Access is giving.
>>>Query Statement:
SELECT COUNT(*) AS ["Planned Ships"] FROM [SELECT DISTINCT [Part No
2540] FROM RMAs WHERE [Priority] =1] AS [%$##@_Alias] GROUP BY [Part
No 2540];
>>>Thanks in advance.
>>>Troy Lee

Select Count(*) As "Planned Ships" From RMAs WHere Priority = 1

If you're going to group by [Part No 2540], why don't you show it as a
column? It'd be kinda ridiculous to see a list of 1, 20, 12, 15 with no
idea what the value is of the field [Part No 2540] since you'll be
breaking on the different values of the [Part No 2540] field.

You might consider going thru help and reading to understand SQL, Totals
queries, Aggregate functions, where clauses, etc.

Or search Google for info. I entered Access Queries in google and came
up withhttp://www.fmsinc.com/tpapers/queries/for a starter, lots more
available. You really should get a firm background on how to create a
query before designing one.

Wave Insanityhttp://www.youtube.com/watch?v=8LoH6oQzJZs


Access doesn't recognize the Count Distinct function, does it?
Everywhere I have been reading, it says that I have to use a subquery
to use the Distinct function. Is this not true?
I have no idea what you are counting. Do you want a count of 1 for each
value of [Part No 2540]? Or do you want the count for each value in
[Part No 2540] with a priority of 1? If so...

SELECT Table1.Part, Count(Table1.Priority) AS CountOfPriority
FROM Table1
WHERE Table1.Priority)=1
GROUP BY Table1.Part;

If you simply want a count of priority 1s without regard to the part
value...
SELECT Count(Table1.Priority) AS CountOfPriority
FROM Table1
WHERE Table1.Priority=1

I really think you need to study how to create queries in the query builder.

Who Knew
http://www.youtube.com/watch?v=cJmghwq7k2I
Jun 27 '08 #5
Based on your first sentence:

Assuming "Part No 2450" is a field name?

SELECT [Part No 2540], Count(*) FROM RMAS WHERE Priority = 1 GROUP BY
[Part No 2540]

or if we want "[Part No] = 2450" then

SELECT Count(*), FROM RMAS WHERE Priority = 1 AND [Part No] = 2540

On Jun 16, 10:28*am, troy_...@comcast.net wrote:
I am trying to count the total number of units for a given part number
that have a Priority rating of 1. Based upon some research, this is
what I came up with for my query. Access says that I have invalid
bracketing in the Select Distinct statement. The only brackets I
inserted were to delimit the table's field names. Access did the rest.
Also, Access created the second AS bracket group - [%$##@_Alias].

Am I barking up the right tree or is my query statement way off base?
I am not sure where to put the WHERE clause and I don't understand the
bracketing error Access is giving.

Query Statement:
SELECT COUNT(*) AS ["Planned Ships"] FROM [SELECT DISTINCT [Part No
2540] FROM RMAs WHERE [Priority] =1] AS [%$##@_Alias] GROUP BY [Part
No 2540];

Thanks in advance.

Troy Lee
Jun 27 '08 #6
On Jun 16, 12:18 pm, lyle fairfield <lyle.fairfi...@gmail.comwrote:
Based on your first sentence:

Assuming "Part No 2450" is a field name?

SELECT [Part No 2540], Count(*) FROM RMAS WHERE Priority = 1 GROUP BY
[Part No 2540]

or if we want "[Part No] = 2450" then

SELECT Count(*), FROM RMAS WHERE Priority = 1 AND [Part No] = 2540

On Jun 16, 10:28 am, troy_...@comcast.net wrote:
I am trying to count the total number of units for a given part number
that have a Priority rating of 1. Based upon some research, this is
what I came up with for my query. Access says that I have invalid
bracketing in the Select Distinct statement. The only brackets I
inserted were to delimit the table's field names. Access did the rest.
Also, Access created the second AS bracket group - [%$##@_Alias].
Am I barking up the right tree or is my query statement way off base?
I am not sure where to put the WHERE clause and I don't understand the
bracketing error Access is giving.
Query Statement:
SELECT COUNT(*) AS ["Planned Ships"] FROM [SELECT DISTINCT [Part No
2540] FROM RMAs WHERE [Priority] =1] AS [%$##@_Alias] GROUP BY [Part
No 2540];
Thanks in advance.
Troy Lee
Thanks for all the replies and constructive criticisms. Please
understand that I am working with a database not originally created by
me- thus all the crazy field names. As for my question, I did do some
more research and have a better grasp on what I am trying to
accomplish. I got my query to work- (aggregate values for each Part
Number type with a Priority of 1).

This is the code found in SQL view of the Query Design window.

SELECT RMAs.[Part No 2540], RMAs.[Unit Type], Count(RMAs.[RMA #]) AS
[CountOfRMA #], RMAs.Priority
FROM RMAs
GROUP BY RMAs.[Part No 2540], RMAs.[Unit Type], RMAs.Priority
HAVING (((RMAs.Priority)=1));

Now, I want to create a calculated field called Total for all of the
units found by the query. I would like to do this within the same
query, but can't quite figure it out. BTW, the field that I am
currently counting, which is also the PK for the table, is a text
field.

For clarity's sake, the field name [Part No 2540] is in reference to
the fact that we preface all of our units by the first four digits
2540. The stored values for the unit types are an additional 4 digits
appended to this number.
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Toby Dann | last post by:
I have an aggregate query as recordsource for a form to show a list of invoices, including the totals (calculated by the aggregate query - I'm trying to duplicate as little info as possible here)....
5
by: Jim | last post by:
Need help with aggregate function...for each unique product, I need the provider with the cheapest cost factor Here't the table (Table1) ID product provider factor 1 123456 abc...
3
by: eddiec | last post by:
hi everyone, I have a report in an adp that uses aggregate functions in its record source and I am trying to figure out how to filter the records displayed in the report: DoCmd.OpenReport...
1
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT...
1
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
3
by: Raghu | last post by:
Hello all, Can somebody help me hopw to resolve teh probelm of aggregate initialisation in c++. Her eis the piece of code. #include<stdio.h> class MyTest { public:
1
by: R.A.M. | last post by:
Hello, I am learning SQL Server 2005. I have (correctly) written in .NET assembly DemoSQLServer with aggregate function AvgNoMinMax in class Demo and I have added assembly to database...
1
by: codeWarrior007 | last post by:
Hi, i'm running a query and everytime I run the query i get the error: 'Aggregate Type' is not a valid name. Make sure that it does not include invalid characters, punctuation, or is not too...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
2
by: Quasar | last post by:
Good morning :) I'm trying to get useful performance information from my DB2 v8.2 server on Linux. I'm asking your help to see if it's possible to have this kind of report - Number of queries...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.