473,385 Members | 1,449 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,385 software developers and data experts.

Another Access Query problem - help appreciated

69
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):

Expand|Select|Wrap|Line Numbers
  1. ID#     PreID#     PostID#     Dollars
  2. 1         2           1           20
  3. 1         2           1           30
  4. 1         3           1           10
  5. 2         5           3           15
  6. 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
May 8 '07 #1
7 1690
Rabbit
12,516 Expert Mod 8TB
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):

Expand|Select|Wrap|Line Numbers
  1. ID#     PreID#     PostID#     Dollars
  2. 1         2           1           20
  3. 1         2           1           30
  4. 1         3           1           10
  5. 2         5           3           15
  6. 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.
May 8 '07 #2
narpet
69
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.
May 8 '07 #3
JConsulting
603 Expert 512MB
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?

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT iif(Count([PreID#])>3,Count([PreID#]),0) AS Count, [ID#]
  2. FROM Test
  3. WHERE (((test.[ID#])=[PostID#]))
  4. group by [ID#]
  5.  
J
May 8 '07 #4
Rabbit
12,516 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. ID#     PreID#     PostID#     Dollars
  2. 1         2           8           20
  3. 1         2           1           30
  4. 1         3           1           10
  5. 2         5           3           15
  6. 1         4           1           25
So you're saying in this example, the Count would still be 3 correct?
May 8 '07 #5
narpet
69
Yes, this will work for me...

Thanks so much for your help, I really appreciate it.
Rod


How about something like so?

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT iif(Count([PreID#])>3,Count([PreID#]),0) AS Count, [ID#]
  2. FROM Test
  3. WHERE (((test.[ID#])=[PostID#]))
  4. group by [ID#]
  5.  
J
May 8 '07 #6
narpet
69
Yes, the count would still be 3 in that example.

Thanks,
Rodney

Expand|Select|Wrap|Line Numbers
  1. ID#     PreID#     PostID#     Dollars
  2. 1         2           8           20
  3. 1         2           1           30
  4. 1         3           1           10
  5. 2         5           3           15
  6. 1         4           1           25
So you're saying in this example, the Count would still be 3 correct?
May 8 '07 #7
Rabbit
12,516 Expert Mod 8TB
Yes, this will work for me...

Thanks so much for your help, I really appreciate it.
Rod
All set then?
May 8 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
8
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 (!)...
2
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...
5
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...
4
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...
9
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...
8
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...
2
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...
7
JodiPhillips
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...
2
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...
1
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...
0
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...
0
isladogs
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...
0
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...
0
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,...
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: 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$) { } ...
1
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...
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...

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.