日期:2014-05-18  浏览次数:20380 次

在线等待~~SELECT语句
我现在有一张用户表,里边有一个推荐的字段,现在我想查询出所有的用户,使推荐的用户在前边,普通用户跟在被推荐用户之后,这样的语句该如何写,请教各位达人~

------解决方案--------------------
create table test(id int,tj varchar(10))

insert test
select 1, 'A|B|C| ' union all
select 1, 'A|B|D| ' union all
select 1, 'A|B|C|D| ' union all
select 1, 'A|B| '


select *
from test
order by case when charindex( '|D| ', '| '+tj)> 0 then 0 else 1 end