|
Subject:
|
relative size query
|
|
Posted By:
|
noam
|
Post Date:
|
12/11/2005 1:25:12 PM
|
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 By:
|
echovue
|
Reply Date:
|
12/11/2005 2:47:39 PM
|
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 By:
|
noam
|
Reply Date:
|
12/11/2005 6:09:20 PM
|
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 By:
|
mmcdonal
|
Reply Date:
|
12/12/2005 7:41:51 AM
|
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 By:
|
kindler
|
Reply Date:
|
12/12/2005 5:00:51 PM
|
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
|