#### SQLite运算子

SQLite中主要有四种类型的运算符：

• 算术运算运算符
• 运算符
• 逻辑运算符
• 按位运算符

#### SQLite算术运算符

Operator Description Example
+ Addition Operator: It is used to add the values of both side of the operator. a+b = 150
Subtraction Operator: It is used to subtract the right hand operand from left hand operand. a-b = -50
* Multiplication Operator: It is used to multiply the values of both sides. a*b = 5000
/ Division Operator: It is used to divide left hand operand by right hand operand. a/b = 0.5
% Modulus Operator: It is used to divide left hand operand by right hand operand and returns remainder. b/a = 0

#### SQLite比较运算符

Operator Description Example
== It is used to check if the values of two operands are equal or not, if yes then condition becomes true. (a == b) is not true.
= It is used to check if the values of two operands are equal or not, if yes then condition becomes true. (a = b) is not true.
!= It is used to check if the values of two operands are equal or not, if values are not equal then condition becomes true. (a != b) is true.
<> It is used to check if the values of two operands are equal or not, if values are not equal then condition becomes true. (a <> b) is true.
> It is used to check if the values of left operand is greater than the value of right operand, if yes then condition becomes true. (a > b) is not true.
< It is used to check if the values of left operand is less than the value of right operand, if yes then condition becomes true. (a < b) is true.
>= It is used to check if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (a >= b) is not true.
<= It is used to check if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (a <= b) is true.
!< It is used to check if the value of left operand is not less than the value of right operand, if yes then condition becomes true. (a !< b) is false.
!> It is used to check if the value of left operand is not greater than the value of right operand, if yes then condition becomes true. (a !> b) is true.

#### SQLite逻辑运算符

Operator Description
AND The AND operator allows the existence of multiple conditions in an SQL statement’s WHERE clause.
BETWEEN The BETWEEN operator is used to search for values that are within a set of values, given the minimum value and the maximum value.
EXISTS The EXISTS operator is used to search for the presence of a row in a specified table that meets certain criteria.
IN The IN operator is used to compare a value to a list of literal values that have been specified.
NOT IN It is the negation of IN operator which is used to compare a value to a list of literal values that have been specified.
LIKE The LIKE operator is used to compare a value to similar values using wildcard operators.
GLOB The GLOB operator is used to compare a value to similar values using wildcard operators. Also, glob is case sensitive, unlike like.
NOT The NOT operator reverses the meaning of the logical operator with which it is used. For example: EXISTS, NOT BETWEEN, NOT IN, etc. These are known as negate operator.
OR The OR operator is used to combine multiple conditions in an SQL statement’s where clause.
IS NULL The NULL operator is used to compare a value with a null value.
IS The IS operator work like =
IS NOT The IS NOT operator work like !=
|| This operator is used to add two different strings and make new one.
UNIQUE The UNIQUE operator searches every row of a specified table for uniqueness (no duplicates).

#### SQLite按位运算符

SQLite按位运算符对位进行处理，并逐位执行操作。

p q p&q p|q
0 0 0 0
0 1 0 1
1 1 1 1
1 0 0 1

a = 0011 1100

b = 0000 1101

a＆b = 0000 1100

a | b = 0011 1101

〜a = 1100 0011

Operator Description Example
& Binary AND operator copies a bit to the result if it exists in both operands. (a & b) will give 12 which is 0000 1100
| Binary OR Operator copies a bit if it exists in either operand. (a | b) will give 61 which is 0011 1101
~ Binary Ones Complement Operator is unary and has the effect of ‘flipping’ bits. (~a ) will give -61 which is 1100 0011 in 2’s complement form due to a signed binary number.
<< Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. a << 2 will give 240 which is 1111 0000
>> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. a >> 2 will give 15 which is 0000 1111