模糊查询

--%代表匹配0个字符 1个字符或多个字符
-- _代表匹配有且只有1个字符
-- [] 代表匹配范围内
-- [^] 代表匹配不在范围内

select * from Department
select * from [Rank]
select * from People
--查询出姓刘的员工信息
select * from People where PeopleName like '刘%'
--查询出名字含有‘尚’的员工信息
select * from People where PeopleName like '%尚%'
--查询出名字含有'尚'或者'史'的员工信息
select * from People where PeopleName like '%尚%' or PeopleName like '%史%'
--查询出姓刘的员工信息 名字是2个字
select * from People where PeopleName like '刘_'
select * from People where SUBSTRING(PeopleName,1,1)='刘'
and len(PeopleName)=2
--查询名字最有一个字为香 名字一共是三个字的员工信息
select * from People where SUBSTRING(PeopleName,3,1)='香'
and len(PeopleName)=3
select* from People where PeopleName like '__香'
--查询出电话号码开头以138的员工信息
select * from People where PeoplePhone like '138%'
--查询出电话号码开头以138的,第四位好像是7或者8 最后一个号码是5
select* from People where PeoplePhone like '138[7,8]%5'
--查询出电话号码开头为138的,第四位好像是2-5之间 最后一个号码2-3
select* from People where PeoplePhone like '138[2,3,4,5]%[^2,3]'
select* from People where PeoplePhone like '138[2-5]%[^2-3]'

posted @ 2026-05-15 22:10  菜鸟的奋斗军  阅读(13)  评论(0)    收藏  举报