I need to use mssql to create a ranking of some kind. This is the situation:
I need to assign position to a list of students based on thier scores. e.g
Student Score Position
StudentA 56 4
StudentB 78 1
StudentC 66 2
StudentD 56 4
I need to create the positions based on the scores of the ctudents.
I will appreciate any assistance.
Thank you.
The problem is : I have table : -------------------------------- ...User ... Speed(minute)... Maria 0.8 John 0.5 Alan 0.8 Anne 2.0 Smith 1.0 Kate 1.5 Evan 1.5 --------------------------------
---> I wanna set ranking for them such as:
Rank.....User.....Speed(minutes) 1 John 0.5 2 Maria 0.8 2 Alan 0.8 4 Smith 1.0 5 Kate 1.5 5 Evan 1.5 7 Anne 2.0 ---------------------------------
I am having an issue with a SQL query I wrote in SQL 2000. I am almost there but am lacking in one area, hoping a better programmer than me and a fresh set of eyes can pick off my mistake.
The goal is very straight forward, order and rank the following fields: R1.PSWins DESC, R1.PSPoints_Total DESC, R1.PSTBDifference
The issue lies in my sub query in the AND / OR joins... This query will work if I sort and rank on two fields, but if I try three or more it does not work properly.
( SELECT COUNT(*) FROM tblWeeklyStandings_All R2 WHERE R2.AutoPoolID = R1.AutoPoolID AND R2.Week = R1.Week AND ( R2.PSWins > R1.PSWins OR R2.PSWins = R1.PSWins AND R2.PSPoints_Total > R1.PSPoints_Total OR R2.PSPoints_Total = R1.PSPoints_Total AND R2.PSTBDifference < R1.PSTBDifference ) ) + 1 AS Rank
FROM dbo.tblWeeklyStandings_All R1 INNER JOIN dbo.qryUsers_SDR ON R1.AutoPoolID = dbo.qryUsers_SDR.AutoPoolID AND R1.PoolID = dbo.qryUsers_SDR.PoolID WHERE (R1.PoolType = '2007' OR R1.PoolType = '2008') AND (dbo.qryUsers_SDR.OrderBy1 = '6') AND (dbo.qryUsers_SDR.PointSpread = 1)
ORDER BY R1.PSWins DESC, R1.PSPoints_Total DESC, R1.PSTBDifference
At this point I am ready to buy SQL 2005 because I think this gets easier, hoping a 2000 wiz can help me correct my error, or missing "(", or something!
Here are the results: Rank Username Wins Points TB Difference 1. test 0618084 16 50 0 4. test 0618083 16 50 66 3. test 0618081 15 50 55 4. test 0618082 14 50 55 5. admin 2 0 0
As you can see the ranking is not correct. It should be the following: Rank Username Wins Points TB Difference 1. test 0618084 16 50 0 2. test 0618083 16 50 66 3. test 0618081 15 50 55 4. test 0618082 14 50 55 5. admin 2 0 0
Sometimes it works sometimes it does not, frustrating!
In different scenerios, I am ranking the following way when ties occur. My code sometimes does this correctly but as you can see above it fails in certain areas, like it forgets R1.PSWins DESC, R1.PSPoints_Total DESC, R1.PSTBDifference....
Rank 1 Tied 1 Tied 3 4 5 Tied 5 Tied 5 Tied 8
etc...
The most frustrating thing is the sort order is correct, it is the rank sub query that fails under certain scenerious...
I was wondering if someone could help me out. What would be the best way for me to go about determining the sale number from the following table:
applicantID calltime result 1 1/5/05 no sale 1 1/15/05 no sale 1 1/25/05 sale 1 1/26/05 no sale 12 1/5/05 no sale 12 1/15/05 no sale 12 1/16/05 no sale 12 1/25/05 sale 12 1/26/05 no sale
the resulting query would provide: applicantID saleattempt 1 3 12 4
etc. Ultimately, I am trying to figure out how many attempts needed to make a sale.
Hi anyone can tell me how to create a table from an existing table in MSSQL. In oracle we issue " create table <tablea> as select * from <tableb>; " ? Thanks in Advance.
Select order_NO, shiptoname, Shiptoaddress, Shiptocity,shiptostate, shiptozip, EMAILaddress FROM orders;
my question is: If the email exist in the EMAILaddress column then I need to have a Y show in another column called EMAILflag, if the EMAILaddress does not exist then I would need the EMAILflag to be a N.
Hey friends,I want create a database on a usb pendrive and acess it my server isMSSQL 7.0 when ever i plugin the pend drive.Please let me know the the procedure .. this is a chellenging job..Thank Youregards*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
I can create a linked server to another MsSQL from MsSQL,but encounter error when create a linked server to MySQL: Error 7399:OLE DB provider 'MSDASQL' reported an error. Data source name not found and no default driver specified. ......
I have the table creation script and insret record script. This is MySQl Format. What changes I have to do so can I run this scripts into SQL Server 2000. If any body has successfully done it then please tell me the procedure.
hi all, Iam using Activex Script in mssql2000, now i want to run the same in msql 2005. i cant run that script. what can i do to run the script in 2005
Hello there,Now I'm really down, how do I simply create a Table in a database?It must be something likeCreate Table TableName ( column_name data_type ) But first how do I execute that string, so it create the table..And if we get that far, how do you then set a table to primarykey? Hope really for help, because this is a importen thing, and I cant find the answer? :S
hi, I'm creating local cube with Delphi. On my server with MSSQL it work well, but i need to know, which parts of MSSQL is needful to create this local cube (on the server) if i will creat and instal new server with MS SQL.
I am a starter of vb.net and trying to build a web application. Do anyone know how to create a temp table to store data from database? I need to extract data from 3 different tables (Profile,Family,Quali). Therefore, i need to use 3 different queries to extract from the 3 tables and then store it in the temp table. Then, i need to output the data from temp table to the screen. Do anyone can help me?
Having problem completing this query. I have a list of items. Some items need to be grouped by a list, some by a range. I was thinking of useing two tables, one for the items, and one for the groups. The groups would have something like groupid, title, listnumbers, rangelow, and rangehigh. The tables are in sql database. For example: The list of items numbers are 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20. In the group table, it would be listed like this: G1, Group1, 1,, G1, Group1, 6,, G2, Group2, ,2,5 G3, Group3,6,18,20 G3, Group3,7,15,17 G3, Group3,8,14,16 G3, Group3,9,11,13
In this example, Group1 is a list, group2 is a range, and group3 is a list of ranges. I can make a query that pulls all the items just in the groups: SELECT ECC_ITEMS.NBR, Group.Group_Name, Group.Title, ECC_ITEMS.DESCR, ECC_ITEMS.REG_PRC FROM Group, ECC_ITEMS WHERE ECC_ITEMS.NBR Between Group.RangeLow And Group.RangeHigh Or ECC_ITEMS.NBR=Group.GroupItems Now, I am not sure how to put the rest of the items (the ones that aren't in a group) in that query. I was thinking on making a union and the second query being a unmatched query. Not sure how to make it were that query is "unmatched" with a table in the same query. And ideas on how to make the second part of the union query?
I was wondering what kind of SQL statement I would need to do the following:For example I have a table that has an ID (vID) column, product id (vPID) and a timestamp (vTime). What I essentially want to do is go through this table and find the top 10 instances of any vPID. I will illsutrate it below.- vID vPID vTime 1 25 101012323 2 25 101012323 3 09 101012323 4 25 101012323 5 25 101012323 6 11 101012323 7 25 101012323 8 10 101012323 9 10 101012323 10 25 101012323 11 25 101012323 12 25 101012323 13 25 101012323 14 11 101012323 15 25 101012323Now what I want to do is return the top vPID instances from highest to lowest so my output should return 25, 11, 10 etc.I hope what I'm asking made sense to you guys, basically im just looking for the top 10 instances of a any product id (vPID) Thanks.
Hello All, I am working on a ranking scenario for a client and I am stumped. Here's the situation...I have an aggregated table that has number of items sold for a salesperson for a given pay period. My client wants to the top 10 salespeople in a report. If two sales people tie, then they should have the same rank, and then the next salesperson in the ranking should have the appropriate number in the sort order. I am trying to figure out how to accomplish with the rank column below.
My small number of brain cells prohibits me from figuring this out. I've got a table
ProviderName EOPCodeTotalDenied Memorial Hosp66$4,598 Memorial HospA3$2,133 Memorial Hosp22$1,111 Memorial Hosp20$912 Memorial Hosp39$4,321 Memorial Hospb2$62 Parkdate Hospb2$6,251 Parkdate Hosp66$2,346 Parkdate Hosp22$1,252 Parkdate Hosp20$4,056 Stone HospV33$8,059
I need to output this table as below (with a denial rank for each hospital -- DESC sort on TotalDenied). I'm stuck on how to get the DenialRank column to work.
ProviderName EOPCodeTotalDeniedDenialRank Memorial Hosp66$4,5981 Memorial Hosp39$4,3212 Memorial HospA3$2,1333 Memorial Hosp22$1,1114 Memorial Hosp20$9125 Memorial Hospb2$626 Parkdate Hospb2$6,2511 Parkdate Hosp20$4,0562 Parkdate Hosp66$2,3463 Parkdate Hosp22$1,2524 Stone HospV33$8,0591
Im working on a table in SQL server 2005 (sp2). A piece of that table is as below. I need a SQL code that adds a new column called rank that ranks starting from 0 by Tire_ID by date asc. For example, for Tire_ID = 41317 and 41350 the result will look like in the second table:
I have a sales report showing Customer, tons shipped, and sales amount with two parameters: year and month. I want to show the ranking by month by both tons and sales. It is easy enough to sort the results by one of the measures and compute a line number but I can't seem to get the rank function to work to compute the ranking by two different measures.
I have a table that has several dozen account numbers. In the same table, each account number has several thousand control numbers (apparently the person who designed the DB never heard of Dr. Codd).
Anyway, I want to get the last five created control numbers for each account number. I have a "CreatedDateTime" field that I can use to order the control numbers by creation. I can use the Top and Rank functions to get the last five for an individual account number but I cannot seem to produce a solution with the last five for each account number.
USE Billing INSERT INTO tblUser (userId,cpId,userTypeId,userStatusId,gameServiceId) VALUES ('test','1','1','9','6') where userId = id from tbl_account
and
INSERT INTO tblUserInfo (userNumber,userId,cpId,userTypeId,userStatusId,gameServiceId) VALUES ('123','test','1','1','9','6') where userNumber = userNumber and userId = userId from tblUser
Im new when it comes to making SQL queries, so i need help badly.
Basically what i need the query to do is call from a DB "User" id where the id is in Binary data. from that i need it to insert into 2 other tables in the Billing DB.
the UserId needs to be the same in all areas, and when it inserts into tblUserInfo it has to pull from userNumber from tblUser after the rows are entered so that the userNumber in tblUser and tblUserInfo are the same.
Hopefully you can help. if any further information is needed please just ask and ill try to give as much as i know.
i am familiar with php mySql combo, but from now on the boss wants me on MS SQL. i have a little query sender that used mySql and i tried to switch it over to use mssql_functions like: php Code:
When i run my script i get a blank screen. I am already bent out of shape trying to switch from mySql to this. any help would be appreciated. here is my code...
php Code:
Original - php Code
<?php /*Program: mssql_send.php *Desc: PHP program that sends an SQL query to the * MS SQL server and displays the results. */ echo "<html> <head><title>MSSQL Query Sender</title></head> <body>"; if(ini_get("magic_quotes_gpc") == "1") { $_POST['query'] = stripslashes($_POST['query']); } $host="yourhost"; $user="you"; $password="example";
Now, I've been racking my brain on how to list the Buyers and the number of related rows in the Orders table. Add to this that I only want to count the Orders where DatePaid IS NOT NULL.
I have this database running (ignore that that was done in Access, this is being made in Microsoft SQL Server 2005).
What I need to do is if you look at the tbl_events table and the tbl_timekeeperDetails table I need to make a query that:
Lists the names of all timekeepers (whether they are booked for a meeting or not), and the meetings at which they are timekeeping.
The tricky part of this is getting the query to show the timekeepers who aren't assigned to an event.
I have two seperate querys so far, but I'm presuming there must be a way of merging them or something.
I have this code so far: select timekeeperTitle,timekeeperNameFirst,timekeeperNameLast,eventID from timekeeperDetails,events where timekeeperDetails.timekeeperID = events.timekeeperID select timekeeperTitle,timekeeperNameFirst,timekeeperNameLast from timekeeperDetails
If anyone has any ideas, please do post a reply or email me at paul [at] abscond [dot] org
I'm building a standard search function for this project im working on and I wanted to know how could I do the following; Basically want I am using the standard "LIKE" function to search keywords but I also want to rank the returns based on how many matches. For example if someone uses the keywords "dog run park fast" and I have a couple of records that have certain amount combinations with these words, how would I return the one that has the most combinations to the least. If one record had "dog, run,park", another has "dog run" and the last would have "fast". How would I being those results in that order.Thanks for any help.
A few weeks ago i posted this and got it to work perfectly. Now im trying to retreive the '3' closest stores rather than just the '1' closest store. How would I go about doing this? I tried using 'TOP 3' in the subquery but you can only retrieve one value.
Here is the origonal post:
"I have a table containing 100 stores, 5000 customers, and the distance between each store and each customer. I am trying to build a query that simply lists each customer and which store is closest and its distance.
Right now it looks like this: Customer1|store1|33 Customer1|store2|15 Customer1|store3|28 Customer1|store4|35
SELECT CustomerPost, StorePost, StoreName, Distance FROM Customer_Store_Distance2 as T WHERE (Distance = (SELECT MIN(Distance) FROM Customer_Store_Distance2 WHERE CustomerPost = T.CustomerPost))
how I could achieve a ranking number, where I have some grouping involved.I want to have the groups in sets of 4, but if I get to a new person the ranking increases, even if I haven't filled the group. For example:
Name Year Sales Ranking -------------------- ----------- ----------- -------------------- John Smith 2009 1296 1 John Smith 2010 1296 1 John Smith 2011 1296 1 John Smith 2012 1296 1 John Smith 2013 1296 2
[code]....
So, when I get to John's 5 year, the Rank increased. I then only had two more rows before I get to Nina, but the Rank number goes up, as the details are for a different person from the prior user.
Select *, DENSE_RANK() over (Order by Name) + ((RANK() over (Partition by Name Order by Year) - 1) /4) as Ranking from #Test Order by Name, Year
Drop Table #TestThis works for John, but Nina then has a Ranking of 2 for her only year, where as she should be 3. Steve also then has a value one too low for all of his ranks.