夏尔勒克莱尔
2019-06-14 11:37
采纳率: 85.7%
浏览 712

求问大佬哪里出错了?急急急!!!

图片说明

编写一段SQL语言:非 Marketing 部门,男性未婚数量超过其部门总人数 30% 的部门 列:(部门名称)

select DepartmentName from Data
where DepartmentName!= 'Marketing' and MaritalStatus='S' and Gender='M'
group by DepartmentName
having (COUNT(Name)/COUNT*)>30%

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dragon_data 2019-06-14 14:15
    已采纳

    SELECT a.departmentName, a.c, b.d FROM
    (select departmentName,COUNT(*) c from employees where DepartmentName!= 'to' group by departmentName) a LEFT JOIN
    (select count(*) d,departmentName from employees where maritalStatus='S' and gender='M' group by departmentName) b
    ON a.departmentName = b.departmentName
    having (b.d/a.c)>0.3

    点赞 打赏 评论

相关推荐 更多相似问题