当前位置:   article > 正文

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

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

第一遍:

mysql> select 姓名 from employees
    -> where 编号 =
    -> (select 编号 from employees
    -> where 收入 =
    -> select 收入 
    -> from salary
    -> where 编号 = '4')
    -> and 收入 > max(收入 =
    -> select 收入
    -> from salary
    -> where 编号 = 1);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

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

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'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

查询输入的表格错误,将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


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

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

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. 部门名称 = '研发部';
  • 1
  • 2
  • 3
  • 4
  • 5

在这里插入图片描述
over

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/754357
推荐阅读
相关标签
  

闽ICP备14008679号