我在参加【中原银行】的【极客大赛】,请大家支持下我的队伍,给【农夫种豆队】投上您宝贵的一票(微信,无需注册,无需填写手机号码,点击一下即可),谢谢大家;
1、问题
求某部门下的员工是否都交了保险;
2、解答
查询部门总人数
select count(1) from dept a,emp b
where a.deptno = b.deptno
and a.deptno = 01
查询交了保险了部门总人数
select count(1) from dept a ,emp b
where a.deptno = b.deptno
and a.deptno = 01
and b.isinsurance = 'Y';
求两者的差,如果为0,则表示全部交了保险,返回true;否则就是没交,返回false;
select decode (
(select count(1) from dept a ,emp b
where a.deptno = b.deptno
and a.deptno = 01)
-
(select count(1) from dept a ,emp b
where a.deptno = b.deptno
and a.deptno = 01
and b.isinsurance ='Y')
,0,'TRUE','FALSE'
) from dual;
3、分析
这里的
decode(计算公式,正确结果,返回正确结果的信息,返回错误结果的信息);