sql语句like多个条件的写法实例_MsSql

admin 2014年5月2日00:04:30MSSQLSERVER评论1,364 次浏览阅读模式


表A 
no name
1   lu,li,zhang 
2   zhou,wei,liu 
3   li,fang 
表B 
no name  sex
1   li          1
2   lu         0
3   zhou    0
4   zhang  1 

怎么实现

复制代码 代码如下:

select * from A where A.name like (select B.name from B where B.sex=1)


----------------------------------------------------------------------------------------------------------------------------
sqlserver写法

复制代码 代码如下:

select distinct a.no,a.name from a,b where charindex(b.name,a.name)>0 and b.sex=1

 
oracle写法

复制代码 代码如下:

select distinct a.no,a.name from a,b where instr(a.name,b.name)>0 and b.sex=1

----- instr() 定位子串 instr('Hello World', 'or')   返回8


相关文章
weinxin
我的微信
微信扫一扫
admin
  • 本文由 发表于 2014年5月2日00:04:30
  • 转载请务必保留本文链接:https://anyun.org/a/jishuguanzhu/database/mssqlserver/2014/0502/354.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: