一道看似简单的面试题

阅读更多
员工表(emp表)
EmpId EmpName EmpSal(员工薪水)
1 ABC 1200
2 BCD 2000
3 EDF 1400

  薪水级别表(sal表)
MinSal MaxSal SalClass(薪水级别)
1000 1500 1
1800 2200 2
----------------------------------------------------
请使用一条sql语句列车员工号位”1”的姓名,薪水,薪水级别,同级别人数,平均工资?

SELECT
e.EMP_NAME,
e.EMP_SAL,
s.SAL_CLASS,
f.NUM,
f.AVGNUM
FROM
SAL s,
EMP e,
(
SELECT
COUNT(*)AS NUM,
AVG(e1.EMP_SAL)AVGNUM
FROM
EMP e1,
SAL s1
WHERE
s1.MIN_SAL <= e1.EMP_SAL
AND e1.EMP_SAL <= s1.MAX_SAL
AND s1.SAL_CLASS =(
SELECT
s2.SAL_CLASS
FROM
EMP e2,SAL s2
WHERE
e2.EMP_ID = 1 AND
s2.MIN_SAL < e2.EMP_SAL
AND e2.EMP_SAL < s2.MAX_SAL
)
)f
WHERE
e.EMP_ID = 1
AND s.SAL_CLASS =(
SELECT
s3.SAL_CLASS
FROM
SAL s3
WHERE
s3.MIN_SAL <= e.EMP_SAL
AND e.EMP_SAL <= s3.MAX_SAL
)
AND s.MIN_SAL <= e.EMP_SAL
AND e.EMP_SAL <= s.MAX_SAL;


结果:
ABC 1200 1 2 1300

第二题自己写一个JDBC:  就不会了 还有待修炼啊~~~

你可能感兴趣的:(面试,sql)