473,386 Members | 1,715 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,386 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 2125


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
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.