mysql数据操作多表查询⼦查询带IN关键字的⼦查询
1 带IN关键字的⼦查询
#查询平均年龄在25岁以上的部门名
mysql语句多表查询
关键点部门名
以查询员⼯表的dep_id的结果当作另外⼀条sql语句查询条件使⽤什么是快速算法
in (sql语句)
mysql>select dep_id from employee group by dep_id having avg(age) >25 ;
+--------+
| dep_id |
+--------+
|201|
|202|
+--------+
2 rows in set (0.00 sec)
mysql>select name from department where id in (select dep_id from employee group by dep_id having avg(age) >25) ;
+--------------+
| name        |
+--------------+
|⼈⼒资源|
黄安仪的结婚照|销售|
+--------------+
2 rows in set (0.00 sec)
#查看技术部员⼯姓名
mysql>select name from employee where dep_id in (select id from department where name = "技术")  ;
+-----------+
| name      |
+-----------+
| mike      |
| liwenzhou |
+-----------+
2 rows in set (0.00 sec)
#查看不⾜1⼈的部门名golang条件编译
查询部门id 这⾥的部门⼈数⾄少有1⼈以上
⼀个id 对应⼀个员⼯有得id对应多个员⼯
mysql>select dep_id from employee ;
maven离线打包命令+--------+
| dep_id |
+--------+
|200|
|201|
|201|
|202|
|200|
|204|
+--------+
6 rows in set (0.00 sec)
拿到是⾄少有⼀个⼈部门id  取反就是不⾜1⼈的部门id
mysql>select distinct dep_id from employee ;
+--------+
| dep_id |
+--------+
|200|
|201|
|202|
|204|
+--------+
4 rows in set (0.00 sec)
取反
cmd执行bat脚本
mysql>select name from department where id not in(select distinct dep_id from employee) ; +--------+
| name  |
+--------+
|运营|
+--------+
1 row in set (0.00 sec)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。