Sort MySQL common keywords

Sort out MySQL common keywords

1. Demonstration of common keywords

user table structure ( id , name , age , sex ) – number , name , age , gender

name keywords usage
Increase insert insert into user(name, age, sex) values(value 1, value 2, value 3);
delete delete delete from user where condition;
Revise update update user set field1=value1, field2=value2 where condition;
Inquire select select * from user;
deduplication distinct select distinct deduplicated fields from user;
Between between select * from user where age between 20 and 30; ( query for users between 20-30 )
fuzzy matching like select * from user where name like 'zhang_%'; ( where _ matches one character and % matches one or more )
Paging query LIMIT SELECT * FROM user LIMIT 5; ( query the first 5 record rows )
Number of records count select COUNT (*) from user; ( query the number of all records in the user table )
sum sum select sum (age) from user; ( query all age sums )
max min max 、 min select max (age) from user; ( the maximum age is the same as the minimum )
average value avg select avg (age) from user; ( average age of all people )
sort order by select * from user order by age; ( default positive order from small to large, asc positive order, desc reverse order )
grouping group by select sex,count(*) from user group by sex; ( group query for the total number of men and women )
Filter after grouping having In fact, it is similar to the usage of where . After having, you can use the aggregate function where but not. After grouping and filtering, it is recommended to use the having keyword.

Copyright statement : This article is an original article by the blogger and may not be reproduced without the blogger's permission https://blog.csdn.net/qq_44614710/article/details/86763114

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324157740&siteId=291194637