SQL Statement Combat-DML Statement (emphasis)
Select: SELECT * FROM table1 where range
Insert: INSERT INTO table1(filed1,filed2)values (filed1,filed2)
Explanation:filed1,filed2 field name ; filed1,filed2 field value
Delete: Delete from table1 where range
Update: Update table1 set field1=value1 where range
Find: SELECT * from Table1where filed1 like '%value1%'
Explanation: Finding a fuzzy match that contains value1
If the search begins with value1 , then use 'value1%';
If the search ends with value1 : Then use '%value1';
Sort by: SELECT * FROM table1 ORDER by Filed1,filed2[desc]
Explanation: [DESC] Flashback [ASC] Positive Order
Total: Select COUNT (*) as TotalCount from table1
sum: select SUM (field1) as Sumvalue from table1
Average: Select AVG (field1) as Avgvalue from table1
Maximum: select Max (field1) as MaxValue from table1
Minimum: Select min (field1) as MinValue from table1
Practical Practice:
1) Insert
Insert four data to persion_info:
statement: (person_id is self-growing, so do not write)
Insert into Person_info (name,country,salary)
VALUES (' Xiao Zhao ', ' China ', 1200.01),
(' Penny ', ' Shanghai ', 1600.32),
(' Xiao Sun ', ' Guangzhou ', 2000.40),
(' Xiao Li ', ' Zhuhai ', 1670.88);
Execution Result:
2) Update:
If you want to put Xiao Zhao's The Country field is changed to Beijing, then the statement is executed:
Update Person_info Set country = ' Beijing ' WHERE name = ' xiao Zhao ';
The following results are performed:
3) sort
the name order by ordering
statement:SELECT * from Person_info order by name Desc;
Operation Result:
4) Find
find fuzzy match data containing "Zhao", statement ""
Select * from Person_info where name is like ' % Zhao % ' ;
Operation Result:
5) Total
Find The total number of data in Person_info table
statement: Select Count (*) as totalcount from Person_info;
Execution Result:
The visible result is 4, and the field name is totalcount.
6) sum
statement:Select sum (Salary) as Sumvalue from Person_info;
Execution Result:
MySQL Database Basics Learning Notes (iii)