麻烦帮我写一个不复杂的查询语句

creativitysoft 2008-01-03 10:42:09
查询是这样的
对输入的B在字段A中进行查询.

表Tabel1
ID A
1 中国,美国,日本
2 加拿大,中国
...
n 美国,英国

对B的值为中国,英国

要求输出结果为,包含中国或英国的行,谢谢,希望得到效率较高的代码
...全文
72 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackyerror 2008-01-03
  • 打赏
  • 举报
回复

select *
from table_1
where index(a,'中国') > 0 or index(a,'英国') > 0;
wzy_love_sly 2008-01-03
  • 打赏
  • 举报
回复
declare @tb table (id int,a varchar(20))
insert into @tb select 1,'中国,美国,日本'
insert into @tb select 1,'加拿大,中国'
insert into @tb select 1,'美国,英国'
insert into @tb select 1,'美国'

select * from @tb where a like '%[中,英][国]%'

2字的可以
arrow_gx 2008-01-03
  • 打赏
  • 举报
回复
select * from table1 where a like '%中国%' or a like '%英国%' 


-狙击手- 2008-01-03
  • 打赏
  • 举报
回复
select *
from table1
where charindex(','+'中国,英国'+',',','+A+',') > 0 or charindex(','+'英国,中国'+',',','+A+',') > 0

34,588

社区成员

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

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