SQL-练习

本文提供了多个SQL查询示例,涉及根据工资金额查询员工工号和姓名,获取特定员工的出勤率,查找出勤率为0的员工,以及找出出勤率为10且工资低于2500的员工详细信息。这些查询使用了INNER JOIN、EXISTS子句和GROUP BY聚合函数。
摘要由CSDN通过智能技术生成

attend表,字段如下
num,no,attendance
工号、工资编号、出勤率

employee表,字段如下
num,name,sex,age,departmentno
工号、姓名、性别、年龄、部门

wage表,字段如下
no,amount
编号、工资金额

题目:
–1.查询工资金额为8000的职工工号和姓名,降序排列
–方式一
select employee.num, employee.name from employee, attend
where attend.no in (select DISTINCT no from wage where amount = 8000)
and attend.num = employee.num ORDER BY employee.num desc
–方式二
select num, name from employee where EXISTS (
select num from attend WHERE EXISTS ( select DISTINCT no from wage where amount = 8000 and attend.no = wage.no)
and employee.num = attend.num)
ORDER BY employee.num desc

–2.查询张三的出勤率
–方式一
select attendance from attend where exists(
select num from employee where name=”张三”
and attend.num = employee.num)
–方式二
select attendance from attend where

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值