Re: Help with counting only one time
- From: "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
- Date: Fri, 29 Feb 2008 09:34:38 +0900
Ah: so you don't just want to know how many of each row there are.
You want to exclude all but the first row for each order?
You will need a primary key in your table to achieve this. In the following example, I will assume there is a primary key field named ID, and the table is called Table1.
SELECT Table1.*
FROM Table1
WHERE ID = (SELECT Min(ID) AS MinOfID
FROM Table1 AS Dupe
WHERE Dupe.[Order] = Table1.[Order]);
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Cam" <Cam@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:07894683-D7CE-453B-999C-A05215FBC31E@xxxxxxxxxxxxxxxx
Allen,
Thanks for the suggestion, but I am clueless on what to do in the query even
after looking at the link you suggested. I thought maybe if I put some sample
data, then you might help me better with what I am trying to achieve.
Table with the following data:
Part Order Oper WC Date
AAA 123 1000 8951 1/2/08
AAA 123 2000 8951 1/3/08
AAA 123 3000 8951 1/7/08
AAA 123 4000 8951 1/3/08
ABC 205 5000 8951 1/4/08
ABC 205 6000 8951 1/8/08
ABZ 314 1000 8951 1/3/08
AAH 380 2000 8951 1/3/08
result of query data I like to achieve:
Part Order Oper WC Date
AAA 123 1000 8951 1/2/08
ABC 205 5000 8951 1/4/08
ABZ 314 1000 8951 1/3/08
AAH 380 2000 8951 1/3/08
Records that are excluded:
AAA 123 2000 8951 1/3/08
AAA 123 3000 8951 1/7/08
AAA 123 4000 8951 1/3/08
ABC 205 6000 8951 1/8/08
For order with multiple oper, it only returns one order with the lowest oper
number. Thank again.
"Allen Browne" wrote:
Use a subquery to get the unique records, and then count the number of
records in the subquery.
This example works in the Northwind sample database:
SELECT Count("*") AS HowMany
FROM (SELECT DISTINCT OrderID FROM [Order Details]) AS MySource;
If subqueries are new, see:
http://allenbrowne.com/subquery-01.html
If you want a function to return unique counts, see ECount() here:
Extended DCount()
at:
http://allenbrowne.com/ser-66.html
"Cam" <Cam@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B076454D-719D-416C-AF91-0ED58A592169@xxxxxxxxxxxxxxxx
> Hi,
>
> I am trying to run a query to count number of order received in the > week
> (date range). The problem is some order has more than 1 record with
> different
> operation, so if the order 1100 has 10 operations, then it is counting > 10
> instead of 1.
>
> Is there a way in query design to specify that the order is a unique > value
> only? Or how should I go about solving this? Thanks
.
- Follow-Ups:
- Re: Help with counting only one time
- From: Cam
- Re: Help with counting only one time
- References:
- Re: Help with counting only one time
- From: Allen Browne
- Re: Help with counting only one time
- From: Cam
- Re: Help with counting only one time
- Prev by Date: Re: Appending Only New Data to a current Table
- Next by Date: Query for comparison of totals
- Previous by thread: Re: Help with counting only one time
- Next by thread: Re: Help with counting only one time
- Index(es):
Relevant Pages
|