Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2005, 02:25 PM
Registered User
 
Join Date: Dec 2005
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 ..

 
Old December 11th, 2005, 03:47 PM
Friend of Wrox
 
Join Date: Oct 2004
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
 
Old December 11th, 2005, 07:09 PM
Registered User
 
Join Date: Dec 2005
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....

 
Old December 12th, 2005, 08:41 AM
Friend of Wrox
 
Join Date: Mar 2004
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
 
Old December 12th, 2005, 06:00 PM
Friend of Wrox
 
Join Date: Dec 2005
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






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.