MySQL是最常用的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)之一,它使用不同的運(yùn)算符進(jìn)行查詢、過濾和排序。以下是MySQL中的各種運(yùn)算符:
1. 算術(shù)運(yùn)算符:+,-,*,/,% - "+": 加法 - "-": 減法 - "*": 乘法 - "/": 除法 - "%": 取模 示例:SELECT col1+col2, col1-col2, col1*col2, col1/col2, col1%col2 FROM table;
2. 比較運(yùn)算符:=,<>, !=,<,<=,>,>=,BETWEEN,IN,LIKE,IS NULL - "=": 等于 - "<>": 不等于 - "!=": 不等于 - "<": 小于 - "<=": 小于或等于 - ">": 大于 - ">=": 大于或等于 - "BETWEEN": 在范圍內(nèi) - "IN": 在值列表內(nèi) - "LIKE": 匹配字符串 - "IS NULL": 判斷是否為空值 示例:SELECT * FROM table WHERE col1=5; SELECT * FROM table WHERE col1<>5; SELECT * FROM table WHERE col1<5; SELECT * FROM table WHERE col1<=5; SELECT * FROM table WHERE col1>5; SELECT * FROM table WHERE col1>=5; SELECT * FROM table WHERE col1 BETWEEN 5 AND 10; SELECT * FROM table WHERE col1 IN(1, 2, 3); SELECT * FROM table WHERE col1 LIKE '%abc%'; SELECT * FROM table WHERE col1 IS NULL;
3. 邏輯運(yùn)算符:AND,OR,NOT - "AND": 邏輯和 - "OR": 邏輯或 - "NOT": 邏輯否 示例:SELECT * FROM table WHERE col1=5 AND col2=10; SELECT * FROM table WHERE col1=5 OR col2=10; SELECT * FROM table WHERE NOT col1=5;
4. 位運(yùn)算符:&,|,^,~,<<,>>- "&": 按位與 - "|": 按位或 - "^": 按位異或 - "~": 按位取反 - "<<": 左移位 - ">>": 右移位 示例:SELECT col1 & col2, col1 | col2, col1 ^ col2, ~col1, col1<< 2, col1 >>2 FROM table;
以上是MySQL中的一些常用的運(yùn)算符,它們可以幫助我們構(gòu)建完善的查詢語句和數(shù)據(jù)操作。