22,301
社区成员




SELECT case when [user_id]=2 then 5 when [user_id]=5 then 2 else [user_id] end as [user_id],name
,age,phone
FROM [TB] order by [user_id]
[code=SQL]
--> 数据库版本:
--> Microsoft SQL Server 2008 (RTM) - 10.0.1600.22
--> 测试数据:[TB]
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[TB]')
AND type in (N'U'))
DROP TABLE [TB]
GO
---->建表
create table [TB]([user_id] int,[name] varchar(2),[age] int,[phone] int)
insert [TB]
select 1,'张',20,111 union all
select 2,'王',12,222 union all
select 3,'李',31,333 union all
select 4,'赵',15,444 union all
select 5,'袁',23,555 union all
select 6,'孙',47,666
GO
--> 查询结果
SELECT * FROM [TB]
SELECT case when [user_id]=2 then 5 when [user_id]=5 then 2 else [user_id] end as [user_id],name
,age,phone
FROM [TB] order by [user_id]
--> 删除表格
--DROP TABLE [TB]