您的位置:首页 > 数据库

sql模糊查询

2014-07-15 18:57 330 查看
use pubs

--返回au_lname是以r开头的作者信息

select * from authors

where au_lname like 'r%'

--au_lname的最后一个字母是'n',第一个字母是'M'

--并且au_fname的最后一个字母是'r'

select * from authors

where au_lname like 'm%n' and au_fname like '%r'

--au_lname的第三个字母是e ,au_fname倒数第二个字母是o

select * from authors

where au_lname like '__e%' and au_fname like '%o_'

--au_lname只有四个字母

select * from authors

where au_lname like '____'

--au_lname的最后一个字符是a,b,c,d,e中的任意一个

select * from authors

where au_lname like '%[abcde]'

select * from authors

where au_lname like '%[a,b,c,d,e]'

select * from authors

where au_lname like '%[a-e]'

--address的最后三个字母是数字

select * from authors

where address like '%[0-9][0-9][0-9]'

--address的最后两个字母不是数字

select * from authors

where address like '%[^0-9][^0-9]'

--au_lname的第二个字母不是a,b,c,d,e,f中的任意一个

select * from authors

where au_lname like '_[^a-f]%'

--title的首字母是t,c,b中的任意一个,最后一个字母是s

--notes的最后一个字母不能是n

select * from titles

where title like '[t,c,b]%s' and notes like '%[^n]'

 

use pubs

--title包含the书籍

select  * from titles

where title like '%the%'

--au_lname的第二个字母是"%"

--接在转义符号后面的通配符,会失去通配符的意义

select * from authors

where au_lname like '_a%%' escape 'a'

--查找au_lname是以”[x”开头,以”]”结尾,

select * from authors

where au_lname like 't[x%t]' escape 't'

--对返回的结果排序

select * from authors

order by au_lname desc

select * from titles

order by type desc,price asc
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: