日期:2014-05-17 浏览次数:20517 次
-10 5102311966100127 于君 35
-15 5102311955012430 蒋远 30
-9 5102301974040890 胡正 50
0 5102311971082924 李先 40
0 5102311948061725 张德 30
-100 5102311960070425 刘昌 50
-40 5102311948111625 赖正 36
-50 5102311970120325 雷洪 50
-58 5102311973081024 艾维 40
-3 5102311955021124 蒋道 38
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-11-20 17:09:04
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([a] int,[b] bigint,[name] varchar(4),[c] int)
insert [huang]
select -10,5102311966100127,'于君',35 union all
select -15,5102311955012430,'蒋远',30 union all
select -9,5102301974040890,'胡正',50 union all
select 0,5102311971082924,'李先',40 union all
select 0,5102311948061725,'张德',30 union all
select -100,5102311960070425,'刘昌',50 union all
select -40,5102311948111625,'赖正',36 union all
select -50,5102311970120325,'雷洪',50 union all
select -58,5102311973081024,'艾维',40 union ALL
select -3,5102311955021124,'蒋道',38
--------------开始查询--------------------------
SELECT a,b,name,c
FROM (
select * ,ROW_NUMBER()OVER(ORDER BY GETDATE())id
from [huang])a
ORDER BY CASE WHEN name='赖正' THEN 0 ELSE id END
----------------结果----------------------------
/*
a b name c
----------- -------------------- ---- -----------
-40 5102311948111625 赖正 36
-10 5102311966100127 于君 35
-15 5102311955012430 蒋远 30
-9 5102301974040890 胡正 50
0 &