MYSQL study notes-punch 1

Task 1 (3 days)

1.1-MySQL software installation and database foundation

Learning content:
1. Software installation and server settings. http://www.runoob.com/mysql/mysql-install.html
2. Use the graphical interface software Navicat for SQL
3 Basic knowledge of database
a. Database definition
b. Relational database
c Two-dimensional table
d. Row
e. Column
f .Primary key
g. Foreign key
4. MySQL database management system
a. Database
b. Data table
c. View
d. Stored procedure
Reference materials
1. [SQL must know must know] https://u18036366.pipipan.com/fs/18036366 -300877816
2. [MySQL Tutorial] http://www.runoob.com/smysql/mysql-tutorial.html
Additional reference materials:
1. Install Linux on virtual machine https://blog.csdn.net/yang5726685/article/ details/78635388
2. MySQL under Windows 10 https://cloud.tencent.com/developer/article/1010608 3.
Frequently asked questions about installing MySQL on Windowshttps://blog.csdn.net/qq_40942329/article/details/79125366

1.2-MySQL Basics (1) Query Statement

1. Import the sample database, the tutorial https://www.yiibai.com/mysql/how-to-load-sample-database-into-mysql-database-server.html 2.
What is SQL? What is MySQL?
Query statement SELECT FROM
a. Statement explanation
b. Deduplication statement
c. First N statements
3. Filter statement WHERE
a. Statement explanation
b. Operator
4. Group statement GROUP BY
a. Statement explanation b.
HAVING clause
5. Sorting Statement ORDER BY
a. Statement explanation
b. Positive order, reverse order
6. SQL comment
7.
SQL code specification a. [SQL programming format optimization suggestions] https://zhuanlan.zhihu.com/p/27466166
b.[SQL Style Guide] https://www.sqlstyle.guide/

  • The following operations are all run in Navicat for Mysql
  • There is no obvious problem during installation and operation. A new database test is created in mysql for task punching.

Item 1: Find duplicate email addresses (difficulty: easy)

Create an email table and insert the following three rows of data
±—±--------+
| Id | Email |
±—±--------+
| 1 | [email protected] |
| 2 | [email protected] |
| 3 | [email protected] |
±—±--------+

Write a SQL query to find all duplicate email addresses in the email table.
Based on the above input, your query should return the following results:

±--------+
| Email |
±--------+
| [email protected] |
±--------+
Note: All email addresses are in lowercase letters.

-Create table

CREATE TABLE email
(ID INT NOT NULL PRIMARY KEY,
 Email VARCHAR(255) NOT NULL);

-Insert data

INSERT INTO email VALUES('1','[email protected]');
INSERT INTO email VALUES('2','[email protected]');
INSERT INTO email VALUES('3','[email protected]');

-Code (write a SQL query to find all duplicate emails in the email table)

SELECT Email FROM email
GROUP BY Email 
HAVING COUNT(Email) > 1;

-result
Insert picture description here

Project 2: Find a big country (difficulty: easy)

Create the following World table

±-----------±---------±--------±-------------±--------------+
| name | continent| area | population | gdp |
±-----------±---------±--------±-------------±--------------+
| Afghanistan| Asia | 652230 | 25500100 | 20343000 |
| Albania | Europe | 28748 | 2831741 | 12960000 |
| Algeria | Africa | 2381741 | 37100000 | 188681000 |
| Andorra | Europe | 468 | 78115 | 3712000 |
| Angola | Africa | 1246700 | 20609294 | 100990000 |
±-----------±---------±--------±-------------±--------------+

If a country has an area of ​​more than 3 million square kilometers, or (population more than 25 million and gdp more than 20 million), then the country is a big country.
Write a SQL query to output the names, populations, and areas of all major countries in the table.

For example, according to the above table, we should output:

±-------------±------------±-------------+
| name | population | area |
±-------------±------------±-------------+
| Afghanistan | 25500100 | 652230 |
| Algeria | 37100000 | 2381741 |
±-------------±------------±-------------+

-Create table

CREATE TABLE World
(name VARCHAR(50) NOT NULL,
continent VARCHAR(50) NOT NULL,
area INT NOT NULL,
population INT NOT NULL,
gdp INT NOT NULL
);

-Insert data

INSERT INTO World
  VALUES('Afghanistan','Asia',652230,25500100,20343000);
INSERT INTO World 
  VALUES('Albania','Europe',28748,2831741,12960000);
INSERT INTO World 
  VALUES('Algeria','Africa',2381741,37100000,188681000);
INSERT INTO World
  VALUES('Andorra','Europe',468,78115,3712000);
INSERT INTO World
  VALUES('Angola','Africa',1246700,20609294,100990000);

-Code (write a SQL query to output the names, populations and areas of all major countries in the table.)

SELECT name, population, area 
FROM world
WHERE area > 3000000 
OR (population > 25000000 AND gdp > 20000000)

-result
Insert picture description here

Guess you like

Origin blog.csdn.net/Baby1601tree/article/details/88958426