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

查询数据排序问题··············
比如说我要查询:
select * from batch_trx o where o.bat_id in ('HB11BAGBBB','HB11BAGBBA','HB115AEBAA','HB10HA2DCB') 
查询结果为:
HB10HA2DCB
HB115AEBAA
HB11BAGBBA
HB11BAGBBB

如何才能将查询结果以查询前的数据排序出来,不要在输出结果时自动替我排序

我希望的排序结果为:
HB11BAGBBB
HB11BAGBBA
HB115AEBAA
HB10HA2DCB

求助高手帮忙解决下··············

------解决方案--------------------
SQL code
select * from batch_trx o where o.bat_id in ('HB11BAGBBB','HB11BAGBBA','HB115AEBAA','HB10HA2DCB')
order by
  charindex(o.bat_id,'HB11BAGBBB','HB11BAGBBA','HB115AEBAA','HB10HA2DCB')

------解决方案--------------------
SQL code

--> 测试数据:[test]
if object_id('[test]') is not null 
drop table [test]
create table [test](id varchar(10))
insert [test]
select 'HB10HA2DCB' union all
select 'HB115AEBAA' union all
select 'HB11BAGBBA' union all
select 'HB11BAGBBB'


select * from test 
order by id desc

/*
id
HB11BAGBBB
HB11BAGBBA
HB115AEBAA
HB10HA2DCB
*/

--这么不行么?

------解决方案--------------------
SQL code

select * from batch_trx o where o.bat_id in ('HB11BAGBBB','HB11BAGBBA','HB115AEBAA','HB10HA2DCB')
ORDER BY GETDATE()