文本描述
一、按部门名称查询出员工的人数大于等于100的语句.(员工:emp_employee, 部门名称: department,员工姓名chnalias.)SELECT departrnent FROM emp_employee GROUP BY departrnent HAVING COUNT(*) >=100二、把员工的姓名、性别和年龄显示出来。(员工表emp_employee, 员工姓名:chnalias,年龄age,性别:gender。性别表:pub_gendar_info,性别名称:smpalias,与员工表的性别关SELECT e.chnalias,g.smpalias,e.age FROM emp_employee e INNERJOIN pub_gendar g ONe.gendar = g.smpalias三、当部门表的名称为空时,用0来代替。(部门表org_department 名称smpalias)SELECT (CASE WHEN smpalias=’null’ THEN ’0′ ELSE smpalias END) AS ‘部门名称’ FROM org_departmenSelect replace(smpalias,’null’,’0’) fromorg_department四、删除员工表中的姓名重复的数据,只保留重复数据中的一条数据。(员工表emp_employee,员工姓名:chnalias)DELETE FROM emp_employee WHERE id NOT IN ( SELECT MAX(id) AS id FROM emp_employee GROUP BY chnalias )五、有三个部门:1人力资源部,2信息中心,3.安全监察部分别把这个三个部门的人员统计出来。要求用sql语句一行来实现(员工表emp_employee,员工姓名:chnalias,员工表对应的部门id:department.。部门表:org_departmen。部门表的字段:部门名称smpalias,部门主键:id)部门表的id=员工表的department显示的结果应该是:人力资源部 信息中心 安全监察部10 20 30SELECT SUM (f.s1) AS ‘人力资源部’,SUM (f.s2)AS ‘信息中心’, SUM (f.s3)AS ‘信息中心’from(SELECT(CASE WHEN d.smpalias=’人力资源部’ THEN SUM(e.Departid) END) AS s1,(CASE WHEN d.smpalias=’信息中心’ THEN SUM(e.Departid) END) AS s2,(CASE WHEN d.smpalias=’安全监察部’ THEN SUM(e.Depart