操作符
AND操作符
mysql> SELECT prod_id,prod_price,prod_name FROM products WHERE vend_id=1003 AND prod_price<=10; +---------+------------+----------------+ | prod_id | prod_price | prod_name | +---------+------------+----------------+ | FB | 10.00 | Bird seed | | FC | 2.50 | Carrots | | SLING | 4.49 | Sling | | TNT1 | 2.50 | TNT (1 stick) | | TNT2 | 10.00 | TNT (5 sticks) | +---------+------------+----------------+ 5 rows in set (0.00 sec)
OR操作符
mysql> SELECT prod_name,prod_price FROM products WHERE vend_id=1002 OR vend_id=1003; +----------------+------------+ | prod_name | prod_price | +----------------+------------+ | Fuses | 3.42 | | Oil can | 8.99 | | Detonator | 13.00 | | Bird seed | 10.00 | | Carrots | 2.50 | | Safe | 50.00 | | Sling | 4.49 | | TNT (1 stick) | 2.50 | | TNT (5 sticks) | 10.00 | +----------------+------------+ 9 rows in set (0.00 sec)
IN 操作符
mysql> SELECT prod_name,prod_price FROM products WHERE vend_id IN (1002,1003) ORDER BY prod_name; +----------------+------------+ | prod_name | prod_price | +----------------+------------+ | Bird seed | 10.00 | | Carrots | 2.50 | | Detonator | 13.00 | | Fuses | 3.42 | | Oil can | 8.99 | | Safe | 50.00 | | Sling | 4.49 | | TNT (1 stick) | 2.50 | | TNT (5 sticks) | 10.00 | +----------------+------------+ 9 rows in set (0.00 sec)
NOT 操作符
mysql> SELECT prod_name,prod_price FROM products WHERE vend_id NOT IN(1002,1003) ORDER BY prod_name; +--------------+------------+ | prod_name | prod_price | +--------------+------------+ | .5 ton anvil | 5.99 | | 1 ton anvil | 9.99 | | 2 ton anvil | 14.99 | | JetPack 1000 | 35.00 | | JetPack 2000 | 55.00 | +--------------+------------+ 5 rows in set (0.01 sec)
运算符优先级
优 先 级 由 低 到 高 排 列
运 算 符
1
=(赋值运算)、:=
2
II、OR
3
XOR
–
–
5
NOT
6
BETWEEN、CASE、WHEN、THEN、ELSE
7
=(比较运算)、<=>、>=、>、<=、<、<>、!=、 IS、LIKE、REGEXP、IN
8
|
9
&
10
<<、>>
11
-(减号)、+
12
*、/、%
13
^
14
-(负号)、〜(位反转)
15
!
LIKE操作符
百分号(%)通配符
mysql> SELECT prod_id,prod_name FROM products WHERE prod_name LIKE 'jet%'; +---------+--------------+ | prod_id | prod_name | +---------+--------------+ | JP1000 | JetPack 1000 | | JP2000 | JetPack 2000 | +---------+--------------+ 2 rows in set (0.00 sec)
下划线(—)通配符
mysql> SELECT prod_id,prod_name FROM products WHERE prod_name LIKE '_ ton anvil'; +---------+-------------+ | prod_id | prod_name | +---------+-------------+ | ANV02 | 1 ton anvil | | ANV03 | 2 ton anvil | +---------+-------------+ 2 rows in set (0.00 sec)
正则表达式
基础字符匹配
mysql> SELECT prod_name FROM products WHERE prod_name REGEXP '1000' ORDER BY prod_name; +--------------+ | prod_name | +--------------+ | JetPack 1000 | +--------------+ 1 row in set (0.04 sec) mysql> SELECT prod_name FROM products WHERE prod_name REGEXP '.000' ORDER BY prod_name; +--------------+ | prod_name | +--------------+ | JetPack 1000 | | JetPack 2000 | +--------------+ 2 rows in set (0.00 sec)
进行OR匹配
mysql> SELECT prod_name FROM products WHERE prod_name REGEXP '1000|2000' ORDER BY prod_name; +--------------+ | prod_name | +--------------+ | JetPack 1000 | | JetPack 2000 | +--------------+ 2 rows in set (0.00 sec)
匹配几个字符之一
mysql> SELECT prod_name FROM products WHERE prod_name REGEXP '[123] Ton' ORDER BY prod_name; +-------------+ | prod_name | +-------------+ | 1 ton anvil | | 2 ton anvil | +-------------+ 2 rows in set (0.00 sec)
匹配范围
mysql> SELECT prod_name FROM products WHERE prod_name REGEXP '[1-5] Ton' ORDER BY prod_name; +--------------+ | prod_name | +--------------+ | .5 ton anvil | | 1 ton anvil | | 2 ton anvil | +--------------+ 3 rows in set (0.00 sec)
匹配特殊字符
mysql> SELECT prod_name FROM products WHERE prod_name REGEXP '\.' ORDER BY prod_name; +--------------+ | prod_name | +--------------+ | .5 ton anvil | +--------------+ 1 row in set (0.00 sec)
元 字 符
说 明
\f
换页
\n
换行
\r
回车
\t
制表
\v
纵向制表
匹配字符类
类
说明
[:alnum:]
任意字母和数字(同[a-zA-Z0-9])
[:alpha:]
任意字符(同[a-zA-Z])
[:blank:]
空格和制表(同[t])
[:cntrl:]
ASCII控制字符(ASCII 0到31和127)
[:digit:]
任意数字(同[0-9])
[:graph:]
与[:print:]相同,但不包括空格
[:lower:]
任意小写字母(同[a-z])
[:print:]
任意可打印字符
[:punct:]
既不在[:alnum:]又不在[:cntrl:]中的任意字符
[:space:]
包括空格在内的任意空白字符(同[fnrtv])
[:upper:]
任意大写字母(同[A-Z])
[:xdigit:]
任意十六进制数字(同[a-fA-F0-9])
匹配多个实例
元 字 符
说 明
*
0个或多个匹配
+
1个或多个匹配(等于{1,})
?
0个或1个匹配(等于{0,1})
{n}
指定数目的匹配
{n,}
不少于指定数目的匹配
{n,m}
匹配数目的范围(m不超过255)
mysql> SELECT prod_name FROM products WHERE prod_name REGEXP '\([0-9] sticks?\)' ORDER BY prod_name; +----------------+ | prod_name | +----------------+ | TNT (1 stick) | | TNT (5 sticks) | +----------------+ 2 rows in set (0.00 sec)
定位符
元 字 符
说 明
^
文本的开始
$
文本的结尾
[[:<:]]
词的开始
[[:>:]]
词的结尾
mysql> SELECT prod_name FROM products WHERE prod_name REGEXP '^[0-9\.]'; +--------------+ | prod_name | +--------------+ | .5 ton anvil | | 1 ton anvil | | 2 ton anvil | +--------------+ 3 rows in set (0.00 sec)
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算