table1
id name orderid
1 a 0
2 a 1,3
3 a 2,1
4 a 1,2
5 a 2,3想查如下结果:
当id=5时显示 (显示id在orderid中的记录)
id name orderid
2 a 1,3
3 a 2,1
请问大家怎么实现啊?
id name orderid
1 a 0
2 a 1,3
3 a 2,1
4 a 1,2
5 a 2,3想查如下结果:
当id=5时显示 (显示id在orderid中的记录)
id name orderid
2 a 1,3
3 a 2,1
请问大家怎么实现啊?
解决方案 »
- 求一SQL语句
- 求解一个SQL语句的执行效率问题
- SQL语句
- 游标问题
- 在select语句中,如何让精度为4位小数的字段,显示时只显示两位小数?
- 数据库同步复制中LogReader Agent 的问题
- 每次刚打开程序运行时都显示未装载DB_library网络通信?
- 在几百万条数据的表中优化查询的方法有吗?网站上也有几百万条数据,怎么那么快;
- 请问如何写语句才能够做到呢?
- 查询总学分大于40的学生人数是否超过50人,并输出反馈信息?
- SQL SERVER2000 中删除一条带image字段的记录,为什么非常慢?
- 本人新近开通了“数据库模型设计”博客,计划分120天进行数据库模型设计有关实战的连载,希望大家捧场。
insert @t
select 1 , 'a' , '0' union all
select 2 , 'a' , '1,3' union all
select 3 , 'a' , '2,1' union all
select 4 , 'a' , '1,2' union all
select 5 , 'a' , '2,3'
select * from @t
where charindex(','+cast(id as varchar)+',',','+
(select orderid from @t where id=5)+',')<>0
where charindex(cast(id as varchar),(select orderid from table1 where id=5))<>0