employee_info:员工表
eid:员工id,主键
ename:员工姓名
work_age:工龄
company:公司表
cid:公司id,主键
cname:公司名称
status:公司状态(0审核中;1审核通过;2审核驳回;3未审核)
employee_basic:员工公司关系表
eid:员工id
cid:公司id
mobile:手机号
(1)查询公司状态为“审核通过”且公司员工平均工龄大于3的公司个数
select count(*) from employee_info a left join employee_basic b on a.eid=b.eid left join company c on c.cid=b.cid where c.startus = 1 group by c.cid having avg(a.work_age) > 3;
(2)查询每个公司中手机号以11开头的员工个数,结果显示:公司名称、员工数量两列,按照公司id倒序排列,取前3条
select c.cname,count(a.eid) from employee_info a left join employee_basic b on a.eid=b.eid left join company c on c.cid=b.cid where mobile like '11%' group by c.cid order by c.cid limit 3;