数据库第九次作业:连接查询&子查询

一、查询“Chisel”所在车间的车间编号、车间主任姓名、主任联系方式

select no,name,phone from shengdian_workshop where
no in (select shop_no from shengdian_worker where name = "chisel");

 

二、查询所有员工姓名、员工联系电话、车间地址、车间主任姓名、主任联系方式
 

select a.name,a.phone,b.address,b.name,b.phone from shengdian_worker a right join shengdian_workshop b
on a.shop_no = b.no;


三、查询“Chisel”所在车间的所有员工姓名、员工联系电话、车间地址

select a.name,a.phone,b.address from shengdian_worker a inner join  shengdian_workshop b
on a.shop_no = b.no where a.shop_no = "ws1";

 

四、查询生产出质量达标产品的产品编号、员工姓名、员工联系电话

select a.no,b.name,b.phone from shengdian_product a inner join shengdian_worker b
on a.work_no = b.no where is_qualified = "1";

 

五、查询已生产产品车间的车间号、平均工龄
 

select shop_no,avg(seniority) from shengdian_worker where shop_no = "ws2";


六、查询所有产品的产品编号、是否合格(合格返回true不合格返回false)、员工号、员工姓名、员工联系方式、车间编号、车间地址

 

select a.no,a.is_qualified,b.no,b.name,b.phone,c.no,c.address from
shengdian_product a inner join shengdian_worker b
on a.work_no = b.no
inner join shengdian_workshop c
on b.shop_no = c.no;


七、查询员工表中是否存在“common”工种的员工,如果存在则查询员工表“common”工种员工的所有字段信息

select * from shengdian_worker where work_type = "common";

 

八、查询存在离职员工的车间编号、车间主任、主任联系方式
 

select no,name,phone from shengdian_workshop where no
in (select shop_no from shengdian_worker where is_onwork = "0");

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值