用子查询的方法查找研发部比财务部所有雇员收入都高的雇员的姓名

第一遍:

mysql> select 姓名 from employees
    -> where 编号 =
    -> (select 编号 from employees
    -> where 收入 =
    -> select 收入 
    -> from salary
    -> where 编号 = '4')
    -> and 收入 > max(收入 =
    -> select 收入
    -> from salary
    -> where 编号 = 1);

意识到子循环中括号没有加全。
第二遍:

mysql> select 姓名 from employees
    -> where 编号 =
    -> (select 编号 from employees
    -> where 收入 =
    -> (select 收入 
    -> from salary
    -> where 编号 = '4')
    -> and 收入 > max(收入 =
    -> (select 收入
    -> from salary
    -> where 编号 = 1)));
1054 - Unknown column '收入' in 'where clause'

查询输入的表格错误,将employees 改为salary
第三遍:

mysql> select 姓名 from employees
    -> where 编号 =
    -> (select 编号 from salary
    -> where 收入 =
    -> (select 收入 
    -> from salary
    -> where 编号 = '4')
    -> and 收入 > max(收入 =
    -> (select 收入
    -> from salary
    -> where 编号 = 1)));
1111 - Invalid use of group function

```sql


函数使用无效(回课本敲例题了,敲完再来)

mysql> select 姓名 from employees as e,departments as d,salary as a
    -> where 收入 > all
    -> (select 收入 from employees as e,departments as d,salary as s
    -> where e.部门号 = d.部门号 and s.编号 = e.编号 and d.部门名称 = '财务部')
    -> and e.部门号 = d.部门号 and a.编号 = e.编号 and d. 部门名称 = '研发部';

在这里插入图片描述
over

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值