How Do I Create A Ranking Query In MSSQL

Feb 17, 2007

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.

View 3 Replies


ADVERTISEMENT

Query For Ranking

Nov 23, 2004

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
---------------------------------

Anyone can tell me how?
Thanks much

View 2 Replies View Related

Sql 2000 Ranking With Sub Query

Jun 21, 2008

Hello,

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.

Here is my entire query:

SELECT

TOP 100 PERCENT

R1.AutoPoolID,
R1.PoolType,
R1.Week,
R1.Username,
R1.TieBreakerTotal,
R1.Wins,
R1.Losses,
R1.Ties,
R1.TBActual,
R1.TBDifference,
R1.WinPercentage,
R1.Points_Thursday,
R1.Points_Saturday,
R1.Points_Sunday,
R1.Points_Monday,
R1.Points_Total,

(
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...

View 1 Replies View Related

Ranking In SQL 2000 Query Analyzer

Oct 11, 2005

Hello-

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.

Thank you...

ps

View 3 Replies View Related

SQL - Create MSSQL DB

Oct 31, 2005

Hi all,

I am writing an application that is required to create specific Databases on the fly.

I am coding with PHP and have no troubles in creating DB's, example code as follows:


//Create new DB
$create_db = "CREATE DATABASE " . $_POST['name'] . "
ON
( NAME = " . $_POST['name'] . "_dat, FILENAME = 'c:program filesmicrosoft sql servermssqldata\" . $_POST['name'] . ".mdf SIZE = 10,MAXSIZE = 50,FILEGROWTH = 5 )
LOG ON
( NAME = " . $_POST['name'] . "_log, FILENAME = 'c:program filesmicrosoft sql servermssqldata\" . $_POST['name'] . ".ldf',
SIZE = 5MB,MAXSIZE = 25MB,FILEGROWTH = 5MB )";

The problem occurs when I try to view the database through a third party application (MSSQL Manager), it wont appear until its registered.

Therein lies my problem, how to register the database via code or scripts.

Am I even on the right track here?

Regards

Hebbs

View 1 Replies View Related

Create Table In MSSQL

Apr 14, 2000

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.

View 3 Replies View Related

Create A View In MSSQL 2000

Oct 12, 2005

I have created a view in MS SQL2000 as followed:

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.

Any HELP would be GREAT.
Thank You!!

View 3 Replies View Related

How To Create A Database On Pendrive Using MSSQL 7.0??

Jul 20, 2005

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!

View 2 Replies View Related

How To Create A Linked Server To MySQL From MsSQL?

Nov 7, 2005

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.
......

Anyone can help me?
Thanks!

View 6 Replies View Related

How To Run Mysql Create Table Script Into MsSQL

Aug 2, 2006

Dear All,

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.

CREATE TABLE `activity` (
`id` bigint(20) NOT NULL auto_increment,
`object_type` varchar(60) default NULL,
`object_id` varchar(20) default NULL,
`person_id` bigint(20) NOT NULL default '0',
`activity_dtm` datetime NOT NULL default '0000-00-00 00:00:00',
`activity_type_cd` varchar(25) NOT NULL default '',
`description_code` varchar(200) default NULL,
PRIMARY KEY (`id`),
KEY `FK9D4BF30FB4715636` (`activity_type_cd`),
KEY `FK9D4BF30F270CDEE0` (`person_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `activity`
--


-- --------------------------------------------------------

--
-- Table structure for table `actv_type`
--

CREATE TABLE `actv_type` (
`code` varchar(25) NOT NULL default '',
`description` varchar(100) NOT NULL default '',
`void_ind` char(1) NOT NULL default '',
PRIMARY KEY (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `actv_type`
--

INSERT INTO `actv_type` VALUES ('job_create', 'Created job', 'F');
INSERT INTO `actv_type` VALUES ('job_update', 'Changed job', 'F');
INSERT INTO `actv_type` VALUES ('job_void', 'Voided job', 'F');
INSERT INTO `actv_type` VALUES ('job_activate', 'Activated job', 'F');
INSERT INTO `actv_type` VALUES ('job_deactivate', 'Changed job to deactive', 'F');
INSERT INTO `actv_type` VALUES ('job_appl_create', 'Created application', 'F');
INSERT INTO `actv_type` VALUES ('job_appl_update', 'Updated application', 'F');
INSERT INTO `actv_type` VALUES ('intrv_create', 'Created interview', 'F');
INSERT INTO `actv_type` VALUES ('intrv_update', 'Updated interview', 'F');
INSERT INTO `actv_type` VALUES ('person_update', 'Update person', 'F');
INSERT INTO `actv_type` VALUES ('person_create', 'Create person', 'F');
INSERT INTO `actv_type` VALUES ('company_void', 'Voided company', 'F');
INSERT INTO `actv_type` VALUES ('company_create', 'Created company', 'F');
INSERT INTO `actv_type` VALUES ('company_update', 'Updated Company', 'F');


Thanks in Advance.

View 12 Replies View Related

How To Create VBActivex Script(scheduler) Mssql 2005

Mar 13, 2008

 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 

View 2 Replies View Related

Simply Create A Table In A MsSQL Express Database Through ADO.net

May 27, 2008

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

View 4 Replies View Related

Needful Parts Of MSSQL To Create Local Cube

Jan 16, 2004

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.

Thanks for reply.

View 12 Replies View Related

Create Temp Table To Store Data From Database(mssql)

Jun 26, 2007

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?

View 2 Replies View Related

MSSQL Query Help

Dec 9, 2004

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?

View 3 Replies View Related

Ranking

Oct 22, 2007

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. 

View 3 Replies View Related

Need Help!! Ranking

Sep 28, 2000

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.

SalespersonID AmountSold Rank
1 5 1
2 5 1
3 4 3
4 4 3
5 2 5

I need the data in my table to look like the example and I am having a difficult time figuring out how. Any help would be appreciated.

Thanks,
Terry

View 1 Replies View Related

Ranking

Jan 17, 2005

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

Appreciate the help.

Ray

View 5 Replies View Related

Ranking

Feb 14, 2008

Hi guys
I'm trying to figure out how to rank records. From the highest value to the lowest. Can you please help?

View 3 Replies View Related

Ranking From 0

Mar 14, 2008



Hello all

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:

original:








Date
Tire_ID
Truck
Position
Area

10/5/1999 0:00
41317
T110
1
BAG

2/5/2000 0:00
41317
T109
1
BAG

5/9/2000 0:00
41317
T103
6
BAG

11/14/1999 0:00
41350
T109
2
BAG

4/19/2000 0:00
41350
T105
4
BAG

7/5/2000 0:00
41350
T104
4
BAG

9/3/2000 1:00
41350
T104
3
BAG

9/17/2000 1:00
41350
T115
5
BAG

Result( new)









Date
Tire_ID
Truck
Position
Area
rank

10/5/1999 0:00
41317
T110
1
BAG
0

2/5/2000 0:00
41317
T109
1
BAG
1

5/9/2000 0:00
41317
T103
6
BAG
2

11/14/1999 0:00
41350
T109
2
BAG
0

4/19/2000 0:00
41350
T105
4
BAG
1

7/5/2000 0:00
41350
T104
4
BAG
2

9/3/2000 1:00
41350
T104
3
BAG
3

9/17/2000 1:00
41350
T115
5
BAG
4

Thanks in advance

View 5 Replies View Related

Ranking With MDX

Oct 25, 2007



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.

Any ideas?

Thanks.

View 1 Replies View Related

Ranking Within A Set

Oct 16, 2007



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.

Anyone have any ideas?

Thanks.

View 3 Replies View Related

Enquiry On MSSQL Query

Jan 18, 2008

in mysql, we can have

select * from test where date like '%-02-01'

all result that ends with -02-01 will be displayed.

however, if i want to do it in ms sql, may i know what's the syntax for this select....like ?

Thanks.

View 1 Replies View Related

MsSQL 2005 Query Help

May 30, 2008

Code:

Select id from tbl_account in Game_User DB

id is binary data


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.

Thanks

David

View 2 Replies View Related

Mssql Query Sender

May 7, 2007

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:






Original
- php Code




mssql_connect($host,$user,$password);
mssql_select_db($_POST['database']);
mssql_query($cxn,$_POST['query']);
mssql_num_rows($result) == 0;






mssql_connect($host,$user,$password);mssql_select_db($_POST['database']);mssql_query($cxn,$_POST['query']);mssql_num_rows($result) == 0;


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";

/* Section that executes query and displays the results */
if(!empty($_POST['form']))
{
$cxn = mssql_connect($host,$user,$password);
mssql_select_db($_POST['database']);
$result = mssql_query($cxn,$_POST['query']);
echo "Database Selected: <b>{$_POST['database']}</b><br>
Query: <b>{$_POST['query']}</b>
<h3>Results</h3><hr>";
if($result == false)
{
echo "<h4>Error!</h4>";
}
elseif(mssql_num_rows($result) == 0)
{
echo "<h4>Query completed.
No results returned.</h4>";
}
else
{
/* Display results */
echo "<table border='1'><thead><tr>";
$finfo = mssql_fetch_field($result);
foreach($finfo as $field)
{
echo "<th>".$field->name."</th>";
}
echo "</tr></thead>

<tbody>";
for ($i=0;$i < mssql_num_rows($result);$i++)
{
echo "<tr>";
$row = mssql_fetch_row($result);
foreach($row as $value)
{
echo "<td>".$value."</td>";
}
echo "</tr>";
}
echo "</tbody></table>";
}
/* Display form with only buttons after results */
$query = str_replace("'","%&%",$_POST['query']);
echo "<hr><br>
<form action='{$_SERVER['PHP_SELF']}' method='POST'>
<input type='hidden' name='query' value='$query'>
<input type='hidden' name='database'
value={$_POST['database']}>
<input type='submit' name='queryButton'
value='New Query'>

<input type='submit' name='queryButton'
value='Edit Query'>
</form>";
exit();
}

/* Displays form for query input */
if (@$_POST['queryButton'] != "Edit Query")
{
$query = " ";
}
else
{
$query = str_replace("%&%","'",$_POST['query']);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>"
method="POST">
<table>
<tr><td style='text-align: right; font-weight: bold'>
Type in database name</td>
<td><input type="text" name="database"
value=<?php echo @$_POST['database'] ?> ></td>
</tr>

<tr><td style='text-align: right; font-weight: bold'
valign="top">Type in SQL query</td>
<td><textarea name="query" cols="60"
rows="10"><?php echo $query ?></textarea></td>
</tr>
<tr><td colspan="2" style='text-align: center'>
<input type="submit" value="Submit Query"></td>
</tr>
</table>
<input type="hidden" name="form" value="yes">
</form>

</body></html>






<?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"; /* Section that executes query and displays the results */if(!empty($_POST['form'])){  $cxn = mssql_connect($host,$user,$password);  mssql_select_db($_POST['database']);  $result = mssql_query($cxn,$_POST['query']);  echo "Database Selected: <b>{$_POST['database']}</b><br>        Query: <b>{$_POST['query']}</b>        <h3>Results</h3><hr>";  if($result == false)  {     echo "<h4>Error!</h4>";  }  elseif(mssql_num_rows($result) == 0)  {     echo "<h4>Query completed.             No results returned.</h4>";  }  else  {   /* Display results */     echo "<table border='1'><thead><tr>";     $finfo = mssql_fetch_field($result);     foreach($finfo as $field)     {        echo "<th>".$field->name."</th>";     }     echo "</tr></thead>           <tbody>";     for ($i=0;$i < mssql_num_rows($result);$i++)     {        echo "<tr>";        $row = mssql_fetch_row($result);        foreach($row as $value)        {           echo "<td>".$value."</td>";        }        echo "</tr>";     }     echo "</tbody></table>";  }  /* Display form with only buttons after results */  $query = str_replace("'","%&%",$_POST['query']);  echo "<hr><br>      <form action='{$_SERVER['PHP_SELF']}' method='POST'>        <input type='hidden' name='query' value='$query'>        <input type='hidden' name='database'               value={$_POST['database']}>        <input type='submit' name='queryButton'               value='New Query'>        <input type='submit' name='queryButton'               value='Edit Query'>      </form>";  exit();}  /* Displays form for query input */if (@$_POST['queryButton'] != "Edit Query"){   $query = " ";}else{   $query = str_replace("%&%","'",$_POST['query']);}?><form action="<?php echo $_SERVER['PHP_SELF'] ?>"       method="POST"><table> <tr><td style='text-align: right; font-weight: bold'>         Type in database name</td>      <td><input type="text" name="database"            value=<?php echo @$_POST['database'] ?> ></td> </tr>  <tr><td style='text-align: right; font-weight: bold'          valign="top">Type in SQL query</td>     <td><textarea name="query" cols="60"            rows="10"><?php echo $query ?></textarea></td> </tr> <tr><td colspan="2" style='text-align: center'>        <input type="submit" value="Submit Query"></td> </tr></table><input type="hidden" name="form" value="yes"></form> </body></html>

View 2 Replies View Related

SHOW Query For MSSQL

Sep 18, 2004

What would the MySQL equivalent for "SHOW TABLES" and "SHOW FIELDS" be in MSSQL?

View 8 Replies View Related

Help With Tricky Query In MSSQL

Apr 18, 2004

Let's say that I have three tables:

Buyer
------
ID
Name
Adress

Session
-------
ID
Date
Pageviews
Buyer

Orders
-------
ID
DatePaid
Session

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.

Any help would be enourmously appriceated.

View 3 Replies View Related

MSSQL Query Merging...?

May 2, 2007

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

It would be very much appreciated.

View 3 Replies View Related

Search Ranking

Oct 24, 2007

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. 

View 3 Replies View Related

Ranking Top 3 Records.

Jul 28, 2006

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

Customer2|store1|35
Customer2|store2|95
Customer2|store3|28
Customer2|store4|76

I want to get it like this:

Customer1|store2|15
Customer2|store3|28"



Here is the solution:


Code:

SELECT CustomerPost, StorePost, StoreName, Distance
FROM Customer_Store_Distance2 as T
WHERE (Distance =
(SELECT MIN(Distance)
FROM Customer_Store_Distance2
WHERE CustomerPost = T.CustomerPost))

View 10 Replies View Related

Ranking To 2 Decimal

Feb 14, 2005

I have query that calculate percentage. i need to rank it to nearest 2 decimal places

query like

SELECT distinct [table a]/[table b] *100 as percentage
from blabla


results
.........
2.7777
20.125


..
want to get result
3
20

View 4 Replies View Related

Ranking With Groupings

Sep 4, 2015

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.

View 3 Replies View Related

Ranking Function

Dec 14, 2007

I have a rank column and a column with percents. The higher the percent the better the rank. How would I do this?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved