这么长的in..CREATE TABLE #T(id int identity,val int)
INSERT #T(val) VALUES(31132)
INSERT #T(val) VALUES(47100)select *
from tab as a
join #T as b
on a.id=B.val
where a.price<99.0
order by b.id
INSERT #T(val) VALUES(31132)
INSERT #T(val) VALUES(47100)select *
from tab as a
join #T as b
on a.id=B.val
where a.price<99.0
order by b.id
你本身的ID跟IN里面的ID有区别吗……不过就是前者少,后者多的关系……
那直接按本身的ID排列不就得了……
order by charindex(','+ltrim(id)+',',',31132,47100,35675,34210,35119,')
a INT,
b VARCHAR(20),
c DECIMAL(18,2)
)
INSERT #t(a,b,c)
SELECT 1,'x',1.11
UNION ALL
SELECT 2,'y',2.22
UNION ALL
SELECT 3,'x',3.3select * from #t order by charindex(','+LTRIM(a)+',',',2,3,1,')/*
2 y 2.22
3 x 3.30
1 x 1.11
*/
*
FROM
tab
WHERE
price>5.0
AND
price <99.0
AND
id IN (31132,47100,35675,34210,35119,37173,37394,45293,45310,32570,36533,34140,35586,45276,45284,45303,42480,42498,38318,39710,41485,42573,26838,41785,42089,38522,40519,43023,43719,38303,40456,40638,40838,34262,35186,27546,27549,27550,27554,28321,28323,28332,26652,37719,42516,43286,43935,43938,26024,26811,27708,28368,37603,40437,43239,43342,43809,43978,25996,26023,26145,26151,26289,26417,26420,27107,27116,27146,27502,27522)
ORDER BY
CHARINDEX(','+LTRIM(ID)+',',',31132,47100,35675,34210,35119,37173,37394,45293,45310,32570,36533,34140,35586,45276,45284,45303,42480,42498,38318,39710,41485,42573,26838,41785,42089,38522,40519,43023,43719,38303,40456,40638,40838,34262,35186,27546,27549,27550,27554,28321,28323,28332,26652,37719,42516,43286,43935,43938,26024,26811,27708,28368,37603,40437,43239,43342,43809,43978,25996,26023,26145,26151,26289,26417,26420,27107,27116,27146,27502,27522,')
用它搜索到ID后再将ID传回来取数据,分页显示如果没有price的大小限制,问题就很简单,我每次只需要SELECT 10个ID。
但加上PRICE后就不好分页了 :(
恩,这个可以用,我试试看IN里面ID再多些行不。
insert #
select 31132 union all
select 47100 union all
......select
a.*
from
tab a,
#t b
where
a.id=b.id
order by
b.px
几万个,换换 exists ..
from (select 2 a union all select 1 union all select 3) b
/*
2
1
3
*/
select *
from (select 2 a union all select 1 union all select 3) b
order by 1
/*
1
2
3
*/
select *
from (select 2 a union all select 1 union all select 3) b
order by 1 desc
/*
3
2
1
*/
排序的时候join 临时表一下 , order by ID 就好了
1.如果无重复ID的话且长度小于10000的话
写入用字符串 用CHARINDEX(5楼)来做
2.如果有重复ID的话
建一个序列sq来建数据序列
再从临时表里取出
string[] sArray=id.Split(',')
在access下用order by instr(******)函数咋用我给忘了,反正这个可以的,呵呵。