Introduction to creating tables and grouping queries in MySQL
The following together to understand MySQL create tables and group queries, I believe we will certainly benefit a lot after reading, the text is not more refined, I hope MySQL create tables and group queries this short content is what you want.
1. create tables
create table score(
id int,
player varchar(20),
position varchar(20),
score float
);
insert into score values(1,'Harden',' guard', 30.0),(2,'Durant','vanguard', 29.1),(3,' James','vanguard', 28.3),(4,'Anthony Davies','vanguard', 27.8),(5,' Lillard','guard', 27.2);
2. Grouping
SELECT Field Name 1,......
FROM table name
GROUP BY Field Name 1... [HAVING conditional expression]
(2) Categorize player positions and display the total score for each position
select position,sum(score) from score group by position;
(3)Find players with scores greater than 29
select player,sum(score) from score group by player having sum(score)>29.0;
After grouping, you can't use where filter to use having, having to use function
(4)Query player scores greater than 27 and less than 30
select player,sum(score) from score where score>27 group by player having sum(score)< 30;
2. Limit the number of query results using LIMIT
SELECT Field Name 1...... FROM table name LIMIT [OFFSET] Number of records
select from score limit 4;
select from score limit 3,2;
3. alias a table
SELECT * FROM table name [AS] alias;
4. function list
After reading MySQL table creation and grouping query introduction this article, many readers will definitely want to know more related content, if you need to get more industry information, you can pay attention to our industry information column.