Database: Database practice

Disclaimer: This article is a blogger original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/Dreaming5498/article/details/96450326

1. database software installation and configuration

server host installation mariadb server software and remote login database;
installation:

yum install mariadb-server -y

Here Insert Picture Description
Start the service:

systemctl start mariadb
systemctl enable mariadb

Here Insert Picture Description
Configure remote login:

mysql_secure_installation	# 设置本地密码
systemctl stop firewalld.service		# 关火墙
systemctl disable firewalld.service
mysql -uroot -p		   # 进入数据库
grant all privileges on *.* to root@'172.25.254.68' 
identified by 'westos';	
# 允许172.25.254.68使用root用户登陆数据库,密码为westos

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
test:
Here Insert Picture Description

2. N-th high salary: Get here claim 2 high salary salary

Here Insert Picture Description
answer:
Here Insert Picture Description

select Salary from Employee order by Salary asc limit 1,1;

Here Insert Picture Description

3. Score sorting

Write a SQL query to achieve the score rankings. If the two scores are the same, in accordance id descending
order.
Here Insert Picture Description
A:
Here Insert Picture Description

select Id, Score from Score order by Score desc, Id asc;

Here Insert Picture Description

4. Find duplicate e-mail

Here Insert Picture Description
answer:
Here Insert Picture Description

select Email from Email group by Email having count(*)> 1;

Here Insert Picture Description

5. income employees than managers

Here Insert Picture Description
answer:
Here Insert Picture Description

select a.Name from StaffSalare as a,StaffSalare as b 
where a.ManageId = b.Id and a.Salary > b.Salary;

Here Insert Picture Description

6. Never order customers

Here Insert Picture Description
answer:
Here Insert Picture Description

select Name as Customers from Customers 
where not Customers.Id in 
(select Customers from Orders);

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/Dreaming5498/article/details/96450326