472,799 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

Add rank to a Make Table Query & then use for calculation

Bob
Hi all,
I want to incorporate several types of different rankings to a Make
Table Query I have then use the rank for calculations.

I want to calculate rankings based on how much each client has in a
portfolio, so lets say there are 4 portfolios, so each client would
have 4 rankings, dependant upon how much they had in each portfolio
compared to their peers. I then want to use each of those rankings to
run some calculations. I want all of this to go into my table
seamlessly...

Please help!

Jan 25 '07 #1
1 2106


On Jan 24, 11:56 pm, "Bob" <scrawf...@colonialfirststate.com.au>
wrote:
Hi all,
I want to incorporate several types of different rankings to a Make
Table Query I have then use the rank for calculations.

I want to calculate rankings based on how much each client has in a
portfolio, so lets say there are 4 portfolios, so each client would
have 4 rankings, dependant upon how much they had in each portfolio
compared to their peers. I then want to use each of those rankings to
run some calculations. I want all of this to go into my table
seamlessly...

Please help!
tblPortfolios
PID AutoNumber
PortfolioName Text

PID PortfolioName
1 P1
2 P2
3 P3
4 P4
5 P5

tblClients
CID AutoNumber
ClientName Text

CID ClientName
1 C1
2 C2
3 C3

tblInvestments
IID AutoNumber
CID Long
PID Long
InventmentAmount Currency

IID CID PID InvestmentAmount
1 1 1 $100,000.00
2 1 2 $50,000.00
3 1 3 $150,000.00
4 2 1 $20,000.00
5 2 3 $3,300,000.00
6 2 4 $80,000.00
7 2 5 $30,000.00
8 3 2 $60,000.00
9 3 4 $20,000.00
10 4 1 $100,000.00
11 4 2 $30,000.00
12 4 3 $5,000,000.00
13 4 4 $145,000.00
14 4 5 $80,000.00

qryRankInvestmentsByPortfolio:
SELECT InvestmentAmount, PID, CID, CStr((SELECT COUNT(*) FROM
tblInvestments AS A WHERE A.PID = tblInvestments.PID AND
A.InvestmentAmount tblInvestments.InvestmentAmount)+(SELECT COUNT(*)
FROM tblInvestments AS A WHERE A.PID < tblInvestments.PID AND
A.InvestmentAmount = tblInvestments.InvestmentAmount)+1) & IIf((SELECT
COUNT(*) FROM tblInvestments AS A WHERE A.IID <tblInvestments.IID AND
A.PID = tblInvestments.PID AND A.InvestmentAmount =
tblInvestments.InvestmentAmount)=0,'',' (tie)') AS RankWithinPortfolio
INTO tblSeamless FROM tblInvestments GROUP BY InvestmentAmount, PID,
CID, IID ORDER BY PID, CID;

!qryRankInvestmentsByPortfolio =tblSeamless

InvestmentAmount PID CID RankwithinPortfolio
$100,000.00 1 1 1 (tie)
$20,000.00 1 2 3
$100,000.00 1 4 1 (tie)
$50,000.00 2 1 2
$60,000.00 2 3 1
$30,000.00 2 4 3
$150,000.00 3 1 3
$3,300,000.00 3 2 2
$5,000,000.00 3 4 1
$80,000.00 4 2 2
$20,000.00 4 3 4
$145,000.00 4 4 1
$30,000.00 5 2 3
$80,000.00 5 4 2

Note that the first two subqueries can be combined into one. I left
them as two separate subqueries so that the individual components can
be seen more easily. This is the only data I tried.

Also, c.f.:

http://groups.google.com/group/micro...120969c917495a

James A. Fortune
CD********@FortuneJames.com

Jan 25 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: maceo | last post by:
I have some code that extracts the data from a table and performs a calculation (total time) on one of the columns. Here is the code: <?php /* Database connection */
3
by: bughunter | last post by:
I discover next problem I have view definition with rank() create view vTEST as select c1, c2, c3, ... -- problem area start , rank() over (order by c3) as RNK -- problem area stop from...
3
by: Elden Carnahan | last post by:
I am trying to derive rank values in a query, just as one would with the Rank function in Excel. Can't see how to do this elementary task. Can anyone advise?
0
by: leavandor | last post by:
I am trying to design a query that works with a relationship between a Table and a Query. I am comparing a value in the table with a computed value inside the query. The reason for this is that...
3
by: jim_geissman | last post by:
I would like to write a query that gives me the values of a set of observations, and their rank. CREATE TABLE #Values(val int) INSERT #Values SELECT 1 INSERT #Values SELECT 5 INSERT #Values...
9
by: Mohd Al Junaibi | last post by:
Hello all, my first post here...hope it goes well. I'm currently working on stored procedure where I translated some reporting language into T-SQL The logic: I have a group of tables...
2
by: orenlevy1 | last post by:
Hi Everyone. I have a problem that I could not figure out what to do with it. I have a couple of tables and views. All have the same unique ID. When a user try to do a search on our web site...
6
by: sstidham | last post by:
I have a query which calculates the data from two table and then yields the number of points based on various calculations for each category. Essentially we are trying to rank our Agents based on...
6
by: vegetable21 | last post by:
Hi All, I'll try and explain as best as possible what I'm trying to do and hopefully someone can tell me the best way to do it! I'm basically trying to rank by 2 columns in mysql/php, by this i...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.