Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 11th, 2005, 02:25 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default relative size query

hi
I want to buid a query that will show me the relative size of data in a table. for example i have a table with names and age:

noam : 27
david : 34
gili : 24
shelly 34

the query should give me :
david : 1
shelly : 1
noam : 2
gili : 3

i think it needs a subquery on the select field but i dont know ...
thanks noam ..

Reply With Quote
  #2 (permalink)  
Old December 11th, 2005, 03:47 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I think you should be able to do it with the following...

Add the name field to your query twice. Then hit the Group By button at the top of the Query Window (Its the thing that looks kind of like an 'E'.

On the second Name, click the drop down on Group By, and choose Count.

Yell if you need more info on this one,

Mike

Mike
EchoVue.com
Reply With Quote
  #3 (permalink)  
Old December 11th, 2005, 07:09 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry but that dosent give me what i wanted , you did not refer to the age of the person at all ...
i need to do a ranking between all the persons by age , take a look again at my request please....

Reply With Quote
  #4 (permalink)  
Old December 12th, 2005, 08:41 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Actually, you asked to show the relative "size of data", not the descending order of each person by age ("i need to do a ranking between all the persons by age.")

However, that would look like:

David
Shelly
Noam
Gili

But would not look like:

David 1
Shelly 1
Noam 2
Gili 3

In fact, it would look like this in a report where you added a number column (you wouldn't necessariy add this in the query results):

David 1
Shelly 2
Noam 3
Gili 4

I am thinking the only way to add this would be through code. You would have to do a query just on the age field first, and then select Unique Values = Yes. Order By Age DESC. Then you could add a number column to rank them. I am not sure how to do this other than to create a table called tblAgeRank with two fields, Age and Rank.

Then do a DELETE query on the table, then do an APPEND query, which would be the query in the last paragraph, and put the rank in with that query.

Then do a thrid query that matches the original table data (Name field, Age field) against tblAgeRank Age field, and then add the Rank field to your query.

Kind of the long way around. I could code this. I am sure another poster has a more elegant solution.

HTH



mmcdonal
Reply With Quote
  #5 (permalink)  
Old December 12th, 2005, 06:00 PM
Friend of Wrox
 
Join Date: Dec 2005
Location: , , .
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What you're attempting should probably be done using VB and DAO RecordSets to parse the sorted (descending) age table, and create a new table based on those results. You shouldn't need to add a new column to the original table, just some code like:

Set rst 'blah blah blah
If Not rst.BOF And Not rst.EOF
rst.MoveFirst
colName = rst.Name
colAge = rst.Age
rank = 1
rst.MoveNext
Do Until rst.EOF
If colAge = rst.Age Then
'Add colName, Rank to new table
Else
'Add colName, Rank to new table
Rank = Rank + 1
End If
'Add colName, Rank (not sure about this, figure out if necessary to avoid off-by-one error

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 97 Query Size Limit chubnut Access 2 October 20th, 2008 04:07 AM
sql query builder windw size problem the_dude ASP.NET 2.0 Basics 0 January 25th, 2007 01:37 PM
Position: relative; czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 April 7th, 2005 11:22 AM
Relative URLs? groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 21 December 16th, 2004 10:53 AM



All times are GMT -4. The time now is 04:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.