Please express your doubts about the database

Previous blog

Those things about the database

Data manipulation language

  1. MySQL's operator
    concept : Operators are symbols that tell MySQL to perform special arithmetic or logical operations.
    Arithmetic operators are used for various numerical operations
    + (addition),-(subtraction), * (multiplication), / (division), remainder (or modular operation, %)
select 1+2;加法
select 2-1;减法
select 2*3;乘法
select 5/3;除法
select 5 div 2;-- 做除法,结果为整数
select 5 % 2, mod(5,2);模运算
  1. The
    concept of comparison operators : the result of a comparison operator is always 1 (true), 0 (false), or null.
    比较运算符可以用于比较数字和字符串
    Comparison operator

HR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzUxMjU5Mjkz,size_16,color_FFFFFF,t_70#pic_center)
Let me briefly introduce the usage of some simple operators
like operator, used to match strings. The syntax format is: expr like 匹配格式*If expr meets the matching conditions, the return value is 1 (true); otherwise, it returns 0 (false). If either expr or matching condition is null, the result is null.
The like operator can use the following two wildcards when matching:

  • '%', matches any number of characters, even 0 characters.
  • '_', only one character can be matched.
    The regexp operator is used to match strings. The syntax format is: expr regepxmatch conditions. If expr meets the matching condition, the return value is 1 (true); otherwise, it returns 0 (false). If either expr or matching condition is null, the result is null.
    The following wildcards are commonly used in regexp operators:
  • '^', matches the string beginning with the character following the character.
  • '$', matches the character string ending with the character after the character.
  • '.', matches any single character.
  • '[Put the character you want to match]', match any character in the square brackets.
  • '*', matches 0 or more characters before it.
  1. The
    concept of logical operators : In SQL, the results of the evaluation of all logical operators are true, false, or null.
    Logical Operators
  2. Bit operation operator
    concept : The operands involved in the operation are operated on binary bits.
    Bitwise operator
    After learning the operators in MySQL, let's take a look at the precedence of operators.
    Operator precedence
  3. Escape characters in mysql
    Escape character
  4. Insert data table
为表的所有字段插入数据,字段名列表默认是全部字段,也可以指定字段。
insert into 表名(字段名列表) values (值列表);
insert into 表名(字段名列表) values (值列表1),(值列表2),...,(值列表n);       同时插入多条记录。
  1. Insert query results into the table
insert语句用来给数据表插入记录时,指定插入记录的列值。
insert into 表名1(字段名列表1) select(字段名列表2) from 表名2 where (条件表达式);

The table name 1 is the table to be inserted into the data, and the rest can be deduced by analogy.
statement: Field name list 1 and field name list 2 must have the same number of fields and the same data type; "conditional expression" specifies selectthe query conditions of the statement.

  1. Modify table data
update 表名 set 字段名1=新值1, 字段名2=新值2,...,字段名n=新值n where (条件表达式);

note: Each "column-value" pair is separated by a comma, no comma is required after the last column

  1. Delete table data
delete from 表名 where (要删除的某条数据);

Table name 1
Field name list 2
(Value list 1), (Value list 2),..., (Value list n) 3

Data table query

  • Select the specified field (column)
select 输出表达式;
  • Define field alias
select 字段名 别名;
或者
select 字段名 as 别名; 

prompt: When you want to modify multiple field aliases, remember to separate them with commas.

  • Replace data in query results
select 字段名1,字段名2,...,字段名n,
case 
     when 条件1 then 表达式1 
     when 条件2 then 表达式2
     ...
     else 表达式n
end
from 表名;

Today we will learn these first. Tomorrow we will write about MySQL and 常用函数hope that everyone will support it.

mysql injection common functions (on)


  1. The name of the data table where the record is inserted. ↩︎

  2. Insert a list of field names in the record. ↩︎

  3. Indicates to insert the value list of the field in n records. ↩︎

Guess you like

Origin blog.csdn.net/m0_51259293/article/details/109340722