如题使用in关键字查询多条记录,但希望查询结果不要自动排序。例句:
select ID, Name from stu where ID in (2,3,1)
----查询输出结果:
ID Name
1 aaaa
2 bbbb
3 cccc----我要的结果是:
ID Name
2 bbbb
3 cccc
1 aaaa
select ID, Name from stu where ID in (2,3,1)
----查询输出结果:
ID Name
1 aaaa
2 bbbb
3 cccc----我要的结果是:
ID Name
2 bbbb
3 cccc
1 aaaa
解决方案 »
- 这个问题请高手解决一下,很急,谢谢。
- 请帮我看看这段存储过程怎么个调用
- 存储过程里怎么返回记录总数
- 这个like条件怎么写?
- 比较奇怪的问题,在不同机器上访问数据库总是出错!
- 请高手指路:我从别人的机器上拷贝了SQLserver数据库,怎样在自己的计算机上打开它啊?
- exec ('select * ' + ' from ' + left('sysobjects',10))
- 关于在SQL SERVER中的一个"很难"的查询问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 加高分!!关于oracle的blob字段在vc++的使用
- 用delphi6+SQL2000做一个应用时出现错误提示“list index out of bounds(0)”,请教各位。
- 數量匯入后如何拆分顯示?
- 这个SQL 语句如何写?
order by charindex(',+ltrim(id)+,',',2,3,1,')
ORDER BY CHARINDEX(','+LTRIM(ID)+',',',2,3,1,')
order by charindex(','+ltrim(id)+',',',2,3,1,')
我目前使用的是access好像不支持的。
【表达式中 'charindex' 函数未定义。】
insert #test select 1 ,'aaaa'
insert #test select 2 ,'bbbb'
insert #test select 3 ,'cccc'select * from #test where ID in (2,3,1)
order by charindex(','+ltrim(id)+',',',2,3,1,')
ID Name
----------- ----------
2 bbbb
3 cccc
1 aaaa(3 行受影响)啊ACCESS
恩,不很多。用union all怎么写?
还有说用union all 连接的,我试试这个。要这么干?主要是按选择时的顺序显示。
当选择多个时,不想一个个查询,但也不能改变选择时的顺序,
所以才想办法这sql语句上想办法。
你自己看,你说麻烦不麻烦,呵呵select ID, Name from stu where ID = 2
union all
select ID, Name from stu where ID = 3
union all
select ID, Name from stu where ID = 1
select ID, Name from Protocol where ID = 2 union all
select ID, Name from Protocol where ID = 3 union all
select ID, Name from Protocol where ID = 1但又不确定In里有几个参数的,
哎,还要判断数量循环。