select * from t_question where id in ('5','3','4','8','39')
'5','3','4'是ID号,
这样查出来给自动排序了,
3
4
5
8
39
我想按照我查询的条件排序,如下
5
3
4
8
39
要怎么写??
'5','3','4'是ID号,
这样查出来给自动排序了,
3
4
5
8
39
我想按照我查询的条件排序,如下
5
3
4
8
39
要怎么写??
order by id
declare @t table( [id] int ) insert into @t values( 3)
insert into @t values( 4)
insert into @t values( 5)
insert into @t values( 39)
insert into @t values( 53)
select * from @t where id in ('5','3','4','39')
order by PATINDEX( '%'+ Convert(varchar(30),[id])+',%','5,3,4,39,')
union
select * from t_question where id ='3'
union
select * from t_question where id ='4'
union
select * from t_question where id ='8'
union
select * from t_question where id ='39'
读取相应id,继而从表里读取数据.你这个想法在id量少时还行,太多了就很糟糕了.最好是根据另一个字段来排序,
set @id='5,3,4,39,'
declare @t table( [id] int ) insert into @t values( 3)
insert into @t values( 4)
insert into @t values( 5)
insert into @t values( 39)
insert into @t values( 53)
select * from @t where id in (@id.substring(@id,@id.len-1))
order by PATINDEX( '%'+ Convert(varchar(30),[id])+',%',@id)