| Author |
Topic |
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-07-24 : 09:49:26
|
| Hai friends,This is the Table MdRating .This has rating columni need top 3 rating from the table and the next 2 top rating from the table. |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 09:50:51
|
| eh? ...so just top 5?perhaps you should give us some sample dataEm |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 09:56:03
|
| top 3 next 2 what does that mean? do you mean top 3 in decreasing and top 2 in increasing? |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-07-24 : 10:00:02
|
| ya top 5, but i need to get the top3 in one query and the next 2 in another query.For example,if the rating column has data 1.10 2.62 3.82 4.76 5.88 6.58 7.41i need top 3 answers which are10,62,82 and next 2 answers such as 76,88 |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 10:01:22
|
| so top 5 based on what? is that an ID column?Em |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-07-24 : 10:04:56
|
| order by rating desc |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 10:05:02
|
quote: Originally posted by Kotti ya top 5, but i need to get the top3 in one query and the next 2 in another query.For example,if the rating column has data 1.10 2.62 3.82 4.76 5.88 6.58 7.41i need top 3 answers which are10,62,82 and next 2 answers such as 76,88
SELECT TOP 3 ID,Answer FROM Table ORDER BY IDSELECT TOP 2 Answer FROM Table WHERE ID NOT IN (SELECT TOP 3 ID FROM Table ORDER BY ID)ORDER BY IDdidnt understand the need of seperate queries though |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 10:06:25
|
| but in your example data the top3 and next top 2 you wanted are not based on rating descending?Em |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 10:06:43
|
quote: Originally posted by Kotti order by rating desc
then how do you think 88 will come after 76? |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-07-24 : 10:08:22
|
| i just send an example |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 10:09:31
|
quote: Originally posted by Kotti i just send an example
but it's NOT an example, it's just random nonsense??anyway... visakh's example still holds just order it by what you want instead of IDEm |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 10:11:46
|
quote: Originally posted by Kotti i just send an example
do you mean an example of how the output should not be? Your description and example dont match. |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-07-24 : 10:14:38
|
| i will send once againFor example,if the rating column has data1.102.623.824.765.886.587.41i need top 3 answers which are 88,82,76 in one queryThen next top 2 which are 62,58 |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 10:16:15
|
| then use visakh's example and change the order by....?Em |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
|
|
Sinisa
Starting Member
5 Posts |
Posted - 2008-07-24 : 10:17:09
|
| Something like this:-- top 3SELECT Top 3 XFROM TAbleX-- and next 2SELECT Top 2 A.XFROM(SELECT XFROM TAbleX)A LEFT OUTER JOIN (SELECT Top 3 XFROM TAbleX)BON A.X=B.XWHERE B.X is null |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 10:18:19
|
No, you don't have an order by clausequote: Originally posted by Sinisa Something like this:-- top 3SELECT Top 3 XFROM TAbleX-- and next 2SELECT Top 2 A.XFROM(SELECT XFROM TAbleX)A LEFT OUTER JOIN (SELECT Top 3 XFROM TAbleX)BON A.X=B.XWHERE B.X is null
Em |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-07-24 : 10:18:47
|
| can't get the exact answer |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 10:19:02
|
quote: Originally posted by Kotti i will send once againFor example,if the rating column has data1.102.623.824.765.886.587.41i need top 3 answers which are 88,82,76 in one queryThen next top 2 which are 62,58
try it yourself by modifying from what i provided earlier. |
 |
|
|
Kotti
Posting Yak Master
129 Posts |
Posted - 2008-07-24 : 10:38:24
|
| Tried ,not getting the answer |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 10:39:02
|
| show us what you triedEm |
 |
|
|
Next Page
|