34,590
社区成员
发帖
与我相关
我的任务
分享
IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
create table tb
(
blogid int,
blogclass varchar(30)
)
insert into tb values(1,'人生');
insert into tb values(2,'学习');
insert into tb values(3,'工作');
insert into tb values(4,'感情');
insert into tb values(5,'朋友');
insert into tb values(6,'娱乐');
go
declare @blogid int
set @blogid=3
select *
from tb
order by case when blogid =@blogid then 0 else blogid end
blogid blogclass
----------- ------------------------------
3 工作
1 人生
2 学习
4 感情
5 朋友
6 娱乐
(6 行受影响)
---楼主看 case when 1 then 2 也可以
IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
create table tb
(
blogid int,
blogclass varchar(30)
)
insert into tb values(1,'人生');
insert into tb values(2,'学习');
insert into tb values(3,'工作');
insert into tb values(4,'感情');
insert into tb values(5,'朋友');
insert into tb values(6,'娱乐');
go
declare @blogid int
set @blogid=3
select *
from tb
order by case when blogid =@blogid then 2 else 3 end ,blogid
declare @blogid int
set @blogid=3
select *
from tb
order by case when blogid =@blogid then 1 else 2 end ,blogid
/*blogid blogclass
----------- ------------------------------
3 工作
1 人生
2 学习
4 感情
5 朋友
6 娱乐
(所影响的行数为 6 行)
*/
-- =========================================
-- -----------t_mac 小编-------------------
--------------------希望有天成为大虾----
-- =========================================
IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
create table tb
(
blogid int,
blogclass varchar(30)
)
insert into tb values(1,'人生');
insert into tb values(2,'学习');
insert into tb values(3,'工作');
insert into tb values(4,'感情');
insert into tb values(5,'朋友');
insert into tb values(6,'娱乐');
go
declare @blogid int
set @blogid=3
select *
from tb
order by case when blogid =@blogid then 0 else 1 end ,blogid
blogid blogclass
----------- ------------------------------
3 工作
1 人生
2 学习
4 感情
5 朋友
6 娱乐
(6 行受影响)