MySQL's advanced additions, deletions, and changes

1. Select all/distinct field name/alias from table where condition + [1] + [2] + [3];

where conditions: >, <, ≥, ≤, like, between and (closed interval), in, not in, and &&, or ||, not!

all: query to all

distinct: remove duplicate results

[1]: group by [asc/desc] asc: ascending order, desc: descending order

【2】:order by

[3]: limit limit 3: Take the first 3 records; limit 2,3: Starting from the third record, take a total of 3 records (starting from position 2, length is 3)

1. Demonstration by example

First build a table, id is the primary key (primary key), and auto-increment (auto_increment)

create table testabc (id int primary key auto_increment,name varchar(4));

adding data

insert into testabc set name='a';

Bulk add

insert into testabc (name) values ('a'),('b'),('c'),('c'),('a'),('a');

select * from testabc where name='a';

select * from testabc group by name;

Limit the first 3 select * from testabc limit 3;

select * from testabc limit 2,3; starting from the third record, take a total of 3 records (starting from position 2, length is 3)

 

2. Commonly used functions max(), min(), avg(), count(), count()---When the record value is NULL, the number of entries is not counted

1. For example, the table is as follows

select max(age) from stu;

select sex, count(*) from stu group by sex;

select sex,count(*),max(age),avg(age) from stu group by sex;

 

Guess you like

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