首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-03-06 
有没有类似于 like in 的查询方法举例我要在表a name 字段中查询表aidnamecountry1汽车中国、印度2纺织品美

有没有类似于 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 + '%' 

热点排行