Verified Commit 77316754 authored by Kiryuu Sakuya's avatar Kiryuu Sakuya 🎵
Browse files

Update No.7

parent 6175bc16
# 实验五
## 名词解释
## 预想的表结构
### 示例代码
#### 1. 创建一个试图,该视图只包含上海客户信息(客户号、客户姓名、住址)
#### 2. 对视图添加一条记录数据
> 注意:分别查看 `customer` 表和该视图的结果。
#### 3. 删除视图中所有姓「王」的客户数据
#### 4. 通过视图修改表内某一客户姓名
#### 5. 有两个基本表 `employee` 和 `sales`,创建一个视图,该视图包含相同业务员的编号、姓名、订单号和销售总金额
#### 6. 将上述视图中订单号为 10001 的记录的销售总金额改为 60000
#### 7. 给上述视图添加一条记录数据
#### 8. 删除上述视图
\ No newline at end of file
......@@ -8,14 +8,53 @@
#### 1. 查找出 sales 表中销售金额最高的订单
#### 2. 查找出 sales 表中订单金额大于「10002 业务员在 2019-09-03 这天所接任意张订单的金额」的所有订单,并显示承接这些订单的业务员和该条订单的金额
```mysql
SHOW FULL COLUMNS FROM sales;
SELECT * FROM sales ORDER BY tot_amt DESC LIMIT 1;
```
#### 2. 查找出 sales 表中订单金额大于「20001 业务员在 2019-09-03 这天所接任意张订单的金额」的所有订单,并显示承接这些订单的业务员和该条订单的金额
> 未测试!
```mysql
SELECT * FROM sales WHERE tot_amt < MAX (SELECT tot_amt FROM sales WHERE sale_id="20001" AND order_date="2019-09-03") ORDER BY tot_amt;
```
#### 3. 找出公司女业务员所接的订单
```mysql
SELECT * FROM sales WHERE sale_id IN (SELECT emp_no FROM employee WHERE emp_sex="女");
```
#### 4. 找出公司中姓名相同的员工,并且依据员工编号排序识别这些员工的信息
```mysql
SELECT emp_no, emp_name, count(*) AS count FROM employee GROUP BY emp_no HAVING count > 1;
```
#### 5. 找出目前业绩未超过 50 元的员工
```mysql
SELECT emp_no, emp_name FROM employee WHERE emp_no IN (SELECT sale_id FROM sales GROUP BY sale_id HAVING SUM(tot_amt)<50);
```
#### 6. 计算公司内各个部门的工资支出总和
```mysql
SELECT emp_dept AS "部门", SUM(emp_salary) AS "工资总和" FROM employee GROUP BY emp_dept;
```
过滤掉 NaN?
```mysql
SELECT emp_dept AS "部门", SUM(emp_salary) AS "工资总和" FROM employee WHERE emp_dept !="NaN" GROUP BY e
mp_dept;
```
#### 7. 计算每一产品销售数量总和与平均销售单价
```mysql
SELECT prod_id AS "产品编号", SUM(qty) AS "产品销售数量", SUM(qty * unit_price) AS "产品销售总和", SUM(unit_price / qty) AS "产品平均销售单价" FROM sale_item GRO
UP BY prod_id ORDER BY SUM(qty * unit_price) DESC;
```
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment