读书人

有没有类似于 like in 的查询方法,该怎

发布时间: 2012-03-06 20:47:55 作者: rapoo

有没有类似于 like in 的查询方法
举例

我要在表a name 字段中查询

表a

id name country
1 汽车 中国、印度
2 纺织品 美国
3 石油 日本
4 出版物 墨西哥、中国
5 农作物 韩国、日本
6 核废料 朝鲜、加拿大

表b
country
中国
美国
日本

我想做类似 select a.* from a where a.country like in( select country from b )

得到

汽车 中国、印度
2 纺织品 美国
3 石油 日本
4 出版物 墨西哥、中国
5 农作物 韩国、日本

[解决办法]

SQL code
select a.* from a,b  where ','+a.country+',' like '%,'+b.country+',%'
[解决办法]
select a.* from a , b
where '、' + a.country + '、' like '%、' + b.country + '、%'

select a.* from a , b
where charindex('、' + b.country + '、' , '、' + a.country + '、') > 0
[解决办法]
select distinct a.* from a join b where a.country like '%' + b.country + '%'
[解决办法]
SQL code
select  a.* from a join b where a.country like '%' + b.country + '%' 

读书人网 >SQL Server

热点推荐