Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Masum7
Starting Member
33 Posts |
Posted - 2010-06-30 : 04:52:11
|
I have a table like this:id--status----------------1---12---13---04---05---16---0-----------Now what is the best way to select top 50 rows where first 25 will be status=1 and second 25 will be status=0So, the simplest and fastest query will select like this:id--status----------------1---12---15---13---04---06---0-----------Masum |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-30 : 04:59:53
|
select id,status from(select ntile(2) over (order by status desc) as sno,* from table) as torder by snoMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|