工资表
±--------±-------±-------±-------±-----------+
| gz.uid | gz.jb | gz.jj | gz.tc | gz.deptno |
±--------±-------±-------±-------±-----------+
| 1 | 2000 | 3000 | 1500 | 1 |
| 2 | 5000 | 500 | 1000 | 2 |
| 3 | 1500 | 1000 | 3000 | 2 |
| 4 | 3000 | 6000 | 8000 | 3 |
| 5 | 1500 | 2000 | 1800 | 1 |
| 6 | 2500 | 1000 | 1900 | 1 |
±--------±-------±-------±-------±-----------+
部门表
±-----------±---------+
| bm.deptno | bm.name |
±-----------±---------+
| 1 | 销售 |
| 2 | 技术 |
| 3 | 行政 |
±-----------±---------+
员工表
±--------±---------±-----------±--------+
| yg.uid | yg.name | yg.gender | yg.age |
±--------±---------±-----------±--------+
| 1 | zs | M | 28 |
| 2 | ww | F | 36 |
| 3 | zl | F | 48 |
| 4 | pp | M | 44 |
| 5 | wb | M | 32 |
| 6 | TQ | F | 32 |
±--------±---------±-----------±--------+
-
求出公司中每个员工的姓名 和 三类收入中最高的那种收入的类型
select
name ,
greatest(jb, jj,tc) max_gz ,
case when greatest(jb, jj,tc) = jb then ‘jb’
when greatest(jb, jj,tc) = tc then ‘tc’
when greatest(jb, jj,tc) = jj then ‘jj’
else “_”
end as gz_category
from
(select
yg.name ,
gz.jb ,
gz.jj ,
gz.tc
from
yg
join
gz
on
yg.uid = gz.uid) t ; -
求出公司中每个岗位的薪资总和
select
deptno,
sum(jj+tc+jb) sum_gz
from
gz
group by deptno ;
select
bm.deptno ,
bm.name ,
t.sum_gz
from
bm
join
(select
deptno,
sum(jj+tc+jb) sum_gz
from
gz
group by deptno)t
on t.deptno = bm.deptno ;
-
求出公司中每个岗位不同性别员工薪资总和
-
- 求出公司中不同性别、不同年龄阶段(20-30,31-40,41-50)的员工薪资总和