34,587
社区成员
发帖
与我相关
我的任务
分享
--给你参考,按给定的姓名排序
if object_id('test1') is not null drop table test1
create table test1
(姓名 varchar(50))
insert into test1
select '陈太花' union all
select '王伟梁' union all
select '陈菊芳' union all
select '张静' union all
select '徐俭' union all
select '陈敏' union all
select '陈淑琴' union all
select '李文花' union all
select '谢丽萍' union all
select '许惠瑛' union all
select '周季俞' union all
select '张燕' union all
select '陆军' union all
select '盛春芳' union all
select '陈家贵' union all
select '徐渭' union all
select '李玉华' union all
select '陆玲娣' union all
select '鲁春娟' union all
select '赵亮'
select * from test1
order by charindex(','+姓名+',',',陈太花,王伟梁,陈菊芳,张静,徐俭,陈敏,陈淑琴,李文花,谢丽萍,许惠瑛,周季俞,张燕,陆军,盛春芳,陈家贵,李玉华,陆玲娣,鲁春娟,赵亮,徐渭,')
CREATE PROCEDURE p1
@type int
AS
BEGIN
IF(@type=1)
BEGIN
SELECT * FROM B WHERE typeID=1
UNION ALL
SELECT * FROM B WHERE typeID=2
UNION ALL
SELECT * FROM B WHERE typeID=3
END
ELSE IF(@type=2)
BEGIN
SELECT * FROM B WHERE typeID=2
UNION ALL
SELECT * FROM B WHERE typeID=1
UNION ALL
SELECT * FROM B WHERE typeID=3
END
ELSE IF(@type=1)
BEGIN
SELECT * FROM B WHERE typeID=3
UNION ALL
SELECT * FROM B WHERE typeID=2
UNION ALL
SELECT * FROM B WHERE typeID=1
END
END
select * from B order by TypeID desc
select * from B order by NAME,TYPEID dessc
order by TYPEID desc
create table t1
(
id1 int,
name1 varchar(10),
tid int
)
insert into t1
select 1, '张1', 1 union all
select 2, '张2', 1 union all
select 3, '李1', 3 union all
select 4, '李2', 2 union all
select 5, '李3', 2
select * from t1 order by case tid when 3 then 0
when 2 then 1
else 2 end,name1
select B.*,A.TYPE from B inner join A on B.TYPEID=A.ID order by (case A.TYPE when '好' then 1 when '中' then 2 when '差' then 3 end) desc