emp和department表(字段类型见表定义)。其中emp表的departmentCode字段和department表的depcode字段关联。请把入职日期为2010年1月1日之前的职员数据导入empwork表(字段类型见表定义),如果职员薪水低于5000,则薪水加600,如果职员薪水高于8000,则薪水减400。

解决方案 »

  1.   

    insert into  empwork
    select 
    case when sal > 8000 then sal - 400 when sal < 5000 then sal + 600 else sal end sal,
    ...
    from department d,emp e
    where d.depcode = e.depcode
    and e.[入职日期] >= '2010-01-01'
      

  2.   

    emp表与department表关联有什么意义?insert into empwork
    (
      empno,empname,depcode,depname,sal,hiredate
    )
    select a.empno,
           a.ename,
           a.deptno,
           b.dname,
           case when a.sal <5000
                then a.sal+600
                when a.sal >8000
                then a.sal-400
            end,
            a.hiredate
      from emp a,dept b
     where a.deptno = b.deptno
       and a.hiredate <= date '2010-1-1';
      

  3.   

    参考sql:
    insert into empwork
    (
      empno,empname,depcode,depname,sal,hiredate
    )
    select a.empno,
           a.ename,
           a.deptno,
           b.dname,
           case when a.sal <5000
                then a.sal+600
                when a.sal >8000
                then a.sal-400
            end,
            a.hiredate
      from emp a,dept b
     where a.deptno = b.deptno
       and a.hiredate <= to_date( '2010-01-01','YYYY-MM-DD')
       and not exists(select  1 from empwork w where w.empno=a.empno);
    注意避免重复员工插入
      

  4.   

    create table empwork(empid varchar2(5),empname varchar2(8),salary number,deptname varchar2(20))
    as
    (select a.empid,a.empname,a.salary,a.deptname from emp a,department b where a.deptid=b.deptid and rjdate<=to_date('20100101','yyyymmdd'))update empwork
    set salary=salary+600
    where empid in(select empid from empwork where salary<5000)update empwork a
    set salary=salary-400
    where exists(select 1 from empwork where a.empid=empid and salary>8000)