求一个sql代码

来源:百度知道 编辑:UC知道 时间:2024/05/23 20:56:50
譬如 我有一个表 Info 里面有一个字段 ID,ID里的数据时
AA-BB-CC-001
AA-B1-CC-002
AM-BB-CC-001
AA-MM-CC-001

我想查询 符合 AA-*-CC 的所有数据怎么查
sql语句怎么写
select * from Info where ID

select * from Info where ID like '%AA-%-CC%'
该语句所有包含有 “AA-这里试任意的数值-CC” 的都被查询出来

都有问题%这是个通配符 他能代替任何长度的任意字符
这里只有一共2个字符
你要搞明白这点
select * from Info where ID like 'AA-__-CC%'

我有个死办法....
select * from mytest where username like '%AA-%' and username like '%-CC%'

mytest是你的info,username是你的 id

select * from Info where ID like 'AA-%-CC'