23,407
社区成员
发帖
与我相关
我的任务
分享select a.empname 姓名,
a.empsal 薪水,
(select salclass from sal where a.empsal between minsal and maxsal) 薪水级别,
(select count(b.empname)
from emp b, sal c
where c.salclass =
(select salclass
from sal
where a.empsal between minsal and maxsal)
and b.empsal between c.minsal and c.maxsal) 同级别人数,
(select avg(b.empsal)
from emp b, sal c
where c.salclass =
(select salclass
from sal
where a.empsal between minsal and maxsal)
and b.empsal between c.minsal and c.maxsal) 同级别平均
from emp a
where a.empid = '1';
这个稍微好点

select e.empname,
e.empsal,
(select sal.salclass
from sal
where e.empsal between sal.minsal and sal.maxsal) as 级别,
(select count(*)
from emp
where emp.empsal between
(select sal.minsal
from sal
where sal.salclass =
(select sal.salclass
from sal
where e.empsal between sal.minsal and sal.maxsal))
and (select sal.maxsal
from sal
where sal.salclass =
(select sal.salclass
from sal
where e.empsal between sal.minsal and sal.maxsal))) as 人数,
(select avg(emp.empsal)
from emp
where emp.empsal between
(select sal.minsal
from sal
where sal.salclass =
(select sal.salclass
from sal
where e.empsal between sal.minsal and sal.maxsal))
and (select sal.maxsal
from sal
where sal.salclass =
(select sal.salclass
from sal
where e.empsal between sal.minsal and sal.maxsal))) as 平均
from emp e
where e.empid = 1


这个真不错