sql语句in的有关问题

pl_0803 2010-06-01 03:25:07

select * from product where sku in ('119-041','120-051','114-017','101-085','244-079','114-015','238-003','251-012','251-037','243-028','231-364','240-029')


查询出来的产品记录是按照索引顺序排列的,可是我想产品的顺序按照后面的括号里的sku顺序显示,不知道大家有什么方法吗?
...全文
128 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
水族杰纶 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 pl_0803 的回复:]
引用 5 楼 you_tube 的回复:

引用 3 楼 pl_0803 的回复:

引用 1 楼 wufeng4552 的回复:

SQL code
order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')

不太明白呢

SQL code
select * fro……
[/Quote]
那個是字段
我把
字段搞錯了
囧...
--小F-- 2010-06-01
  • 打赏
  • 举报
回复
--应该是
order by charindex(','+ltrim(sku)+',',',119-041,120-051,114-017,101-085....,')
--小F-- 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 pl_0803 的回复:]
引用 5 楼 you_tube 的回复:

引用 3 楼 pl_0803 的回复:

引用 1 楼 wufeng4552 的回复:

SQL code
order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')

不太明白呢

SQL code
select * fro……
[/Quote]
product是列名啊
qiqi860819 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 feilniu 的回复:]
SQL code

select *,
dispseq = charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')
from product where sku in ('119-041','120-051','114-017','101-085','244-079','114-015','……
[/Quote]

up
feilniu 2010-06-01
  • 打赏
  • 举报
回复

select *,
dispseq = charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')
from product where sku in ('119-041','120-051','114-017','101-085','244-079','114-015','238-003','251-012','251-037','243-028','231-364','240-029')
order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')


这样就明白了。

1楼的想法真棒!
pl_0803 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 you_tube 的回复:]

引用 3 楼 pl_0803 的回复:

引用 1 楼 wufeng4552 的回复:

SQL code
order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')

不太明白呢

SQL code
select * from product where sku in ……
[/Quote]
order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')
这个里面的product是什么意思啊?
you_tube 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 pl_0803 的回复:]

引用 1 楼 wufeng4552 的回复:

SQL code
order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')

不太明白呢
[/Quote]
select * from product where sku in ('119-041','120-051','114-017','101-085','244-079','114-015','238-003','251-012','251-037','243-028','231-364','240-029')
order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')

这样
pl_0803 2010-06-01
  • 打赏
  • 举报
回复
大家给出出主意啊!谢谢啊
pl_0803 2010-06-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wufeng4552 的回复:]

SQL code
order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')
[/Quote]
不太明白呢
wlmstar 2010-06-01
  • 打赏
  • 举报
回复
没有简便的方法吧,只能写个split的存储过程,
循环拼sql语句,
拼成如下格式:
select * from product where sku='119-041'
union all
select * from product where sku='120-051'
....
最后
exec ('....')
水族杰纶 2010-06-01
  • 打赏
  • 举报
回复
order by charindex(','+ltrim(product)+',',',119-041,120-051,114-017,101-085....,')

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧