输入表:
EMP
EMPNO ENAME DEPTNO SAL DOJ
100 abc 10 1000 09-Jul-2007
200 def 20 2000 09-Jul-2014
300 ghi 30 3000 09-Jul-2009
400 jkl 40 4000 09-Jul-2010
500 mno 20 5000 09-Jul-2011
600 pqr 30 6000 09-Jul-2012
系
DEPTNO DNAME LOC
10 X BZA
20 Y MTM
30 Z HYB
SAL
SALGRADE LL HL
A 100 1000
B 1001 2000
C 2001 3000
D 3001 4000
E 4001 6000
输出:
EMPNO ENAME DEPTNO SAL DOJ DNAME LOC SALGRADE
100 abc 10 1000 09-Jul-2007 X BZA A
200 def 20 2000 09-Jul-2014 Y MTM B
300 ghi 30 3000 09-Jul-2009 Z HYB C
500 mno 20 5000 09-Jul-2011 Y MTM E
编写一个sql查询来显示输出表。
答案 0 :(得分:0)
请尝试以下方式
第一种方式
select top(4)*,(select salgrade from sal where emp.sal >= sal.LL and emp.sal<= sal.HL) as salgrade
from emp
inner join dept on emp.deptno=dept.deptno
order by empno
第二种方式
select top(4)*
,(select salgrade from sal where emp.sal between sal.LL and sal.HL) as salgrade
from emp
inner join dept on emp.deptno=dept.deptno
order by empno