1. 数据库软件安装与配置
server 主机安装 mariadb 服务器软件并实现远程登录数据库;
安装:
yum install mariadb-server -y

开启服务:
systemctl start mariadb
systemctl enable mariadb

配置远程登录:
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



测试:

2. 第 N 高的薪水: 此处要求获取薪水第 2 高的薪水

答:

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

3. 分数排序
编写一个 SQL 查询来实现分数排名。如果两个分数相同,则按照 id 由大到小进行
排序.

答:

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

4. 查找重复的电子邮箱

答:

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

5. 超过经理收入的员工

答:

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

6. 从不订购的客户

答:

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

本文涵盖了数据库的安装配置,重点讨论了如何查询数据库中第二高的薪水,解决重复电子邮箱的问题,以及找出收入超过其经理的员工和从未下单的客户等实用案例。

被折叠的 条评论
为什么被折叠?



