Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to creating tables and grouping queries in MySQL

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report