SQL statement combat - DML statement (emphasis)
Select: select * from table1 where range
插入:insert into table1(filed1,filed2)values (filed1,filed2)
Explanation: filed1, filed2 field name ; filed1, filed2 field value
Delete: delete from table1 where scope
Update: update table1 set field1=value1 where scope
查找:select * from table1where filed1like ‘%value1%’
Explanation: Find fuzzy matches that contain value1
If the lookup starts with value1 , use ' value1% ' ;
If the search ends with value1 : use ' %value1 ' ;
排序:select * from table1 order by filed1,filed2[desc]
Explanation: [desc] flashback [asc] positive sequence
总数:select count(*) as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
Practical practice:
1) Insert
Insert four pieces of data into persistence_info :
Statement: ( person_id is self-increasing, so do not write)
insert into person_info(name,country,salary)
values ( ' Xiao Zhao ', 'China',1200.01),
(' Little Money ', ' Shanghai ', 1600.32 ),
( ' Xiao Sun ', ' Guangzhou ', 2000.40),
( ' Little Li ', ' Zhuhai ', 1670.88);
Results of the:
2) Update:
If you want to change Xiao Zhao's country field to Beijing, execute the statement:
update person_info set country = ' Beijing ' where name = ' Xiao Zhao ';
The result after execution is as follows:
3) Sort
Sort name by order by
语句:select * from person_info order by name desc;
operation result:
4) Find
Find fuzzy matching data containing "Zhao", the statement ""
Select * from person_info where name like ‘%赵%’;
operation result:
5) Total
Find the total number of data in the person_info table
语句:Select count(*) as totalcount from person_info;
Results of the:
The visible result is 4 , and the field name is totalcount .
6) Summation
语句:select sum(salary) as sumvalue from person_info;
Results of the: