Okay... here's another query that I need to write that I just can't seem to figure out.
first the table layout (table name TEST): - ID# PreID# PostID# Dollars
-
1 2 1 20
-
1 2 1 30
-
1 3 1 10
-
2 5 3 15
-
1 4 1 25
Okay... here's what I need to do. I need to select the records where:
1. the ID# is equal to the PostID# AND
2. the count of distinct values in the PreID# is greater than 2
So with my example, the records with 1 in the ID# field have equal values (1) in the PostID# field, and the distinct count of the PreID# field is 3 (there are two 2s, one 3, and one 4 for a distinct count of 3). I don't care about the Dollars field, I just put it in there to show that duplicate ID#s are okay.
I hope this makes sense...
Is this possible?
Thanks so much in advance,
Rod
7 1690
Okay... here's another query that I need to write that I just can't seem to figure out.
first the table layout (table name TEST): - ID# PreID# PostID# Dollars
-
1 2 1 20
-
1 2 1 30
-
1 3 1 10
-
2 5 3 15
-
1 4 1 25
Okay... here's what I need to do. I need to select the records where:
1. the ID# is equal to the PostID# AND
2. the count of distinct values in the PreID# is greater than 2
So with my example, the records with 1 in the ID# field have equal values (1) in the PostID# field, and the distinct count of the PreID# field is 3 (there are two 2s, one 3, and one 4 for a distinct count of 3). I don't care about the Dollars field, I just put it in there to show that duplicate ID#s are okay.
I hope this makes sense...
Is this possible?
Thanks so much in advance,
Rod
Actually the distinct count is 4. 2,3,5,4. If you're talking about distinct count by grouping, then you'll have to specify what grouping. By ID# and PostID#? By ID# only? By PostID# only? Any one of these can be the case from the example you gave. But it may not be the case for all examples so you'll have to be clearer on this point.
But, in either case you'd use an aggregate query grouping by the ID fields you need and then using a count and setting up the proper criteria.
Actually the distinct count is 4. 2,3,5,4. If you're talking about distinct count by grouping, then you'll have to specify what grouping. By ID# and PostID#? By ID# only? By PostID# only? Any one of these can be the case from the example you gave. But it may not be the case for all examples so you'll have to be clearer on this point.
But, in either case you'd use an aggregate query grouping by the ID fields you need and then using a count and setting up the proper criteria.
Based on my criteria... the distinct count is 3... the number 5 is not in my criteria as stated becaust the ID# (2) is not equal to the PostID# (3), which omits that PreID# (5). This leaves us with PreID#s 2, 3, and 4.
Any ideas on how to specifically write this query? Everything I try tells me that I can't use an aggregrate function in the where clause.
Based on my criteria... the distinct count is 3... the number 5 is not in my criteria as stated becaust the ID# (2) is not equal to the PostID# (3), which omits that PreID# (5). This leaves us with PreID#s 2, 3, and 4.
Any ideas on how to specifically write this query? Everything I try tells me that I can't use an aggregrate function in the where clause.
How about something like so? -
SELECT DISTINCT iif(Count([PreID#])>3,Count([PreID#]),0) AS Count, [ID#]
-
FROM Test
-
WHERE (((test.[ID#])=[PostID#]))
-
group by [ID#]
-
J
- ID# PreID# PostID# Dollars
-
1 2 8 20
-
1 2 1 30
-
1 3 1 10
-
2 5 3 15
-
1 4 1 25
So you're saying in this example, the Count would still be 3 correct?
Yes, this will work for me...
Thanks so much for your help, I really appreciate it.
Rod
How about something like so? -
SELECT DISTINCT iif(Count([PreID#])>3,Count([PreID#]),0) AS Count, [ID#]
-
FROM Test
-
WHERE (((test.[ID#])=[PostID#]))
-
group by [ID#]
-
J
Yes, the count would still be 3 in that example.
Thanks,
Rodney - ID# PreID# PostID# Dollars
-
1 2 8 20
-
1 2 1 30
-
1 3 1 10
-
2 5 3 15
-
1 4 1 25
So you're saying in this example, the Count would still be 3 correct?
Yes, this will work for me...
Thanks so much for your help, I really appreciate it.
Rod
All set then?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Daniel |
last post by:
I use an Access database to basically take data exports, import them,
manipulate the data, and then turn them into exportable reports. I do
this using numerous macros, and queries to get the data...
|
by: John Hardy |
last post by:
I have the following SQL code in my databse as a querry.
SELECT Sheet1.ID, Sheet1.Field6, Sheet2.ID, Sheet2.Field6
FROM Sheet1 INNER JOIN Sheet2 ON Sheet1.ID = Sheet2.ID
WHERE (((!)<>! Or (!)...
|
by: Jeff Barry |
last post by:
Hi,
I wonder if any one can help, I'm pretty new to Access and I can't
figure out how to change the contents of a combo box based on a
selection I make in another.
Let me explain I have a...
|
by: Bec |
last post by:
I'm in desperate need of your help..
I need to build an access database and have NO idea how to do this..
Not even where to start..
It IS for school, and am not asking anyone to do my...
|
by: Takeadoe |
last post by:
Hey Gang, I'm gearing up to retool for the upcoming deer season here in
Ohio and I could use some help with very general questions about
direction. I will be scanning nearly 210,000 forms that...
|
by: sellcraig |
last post by:
Microsoft access
2 tables
table "data main" contains a field called "code"
table "ddw1" is created from a make table query of "data main"
Goal-
the data in "code" field in needs to...
|
by: daD |
last post by:
I'm trying to write a small database that tracks people coming and
going from a small campground. I need to have the current guests in
the "current" table" and then have the ability to check them...
|
by: mudman04 |
last post by:
Hi,
I searched online for some similar issues that I am facing but was not able come up with anything. I am fairly new with Access (2 months experience) and I am trying to remove a message...
|
by: JodiPhillips |
last post by:
Hi,
My first post! I've basically taught myself Access and the little I know about VBA through reading these forums and a couple of books.
I'm in the middle of a project at work - to put it...
|
by: dympna |
last post by:
Hi can anyone suggest a fix for this... as I am a novice in access.
I have created a training table with the following fields
Employee Name - joe
Training Received - Fork lift
Date Received...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |