求一段SQL
需求是:用A表的column1 去匹配B表的一个区间columnX,columnY,得到B表的columnZ,然后用B的columnZ 修改A表的Column2
字段的类型都是number,A和B表没关系
请问这个要怎么写?谢谢了
------解决方案--------------------能不能给出测试数据再问?
------解决方案--------------------需求说的不太清楚,我刚好弄过一个测试例子,你看下是不是差不多这样的:
-- Create table
create table EMPLOYEE
(
EMPNO NUMBER(4),
ENAME VARCHAR2(10),
SAL NUMBER(7,2),
REMARK NUMBER(2)
);
insert into employee (EMPNO, ENAME, SAL)values (7369, 'SMITH', 990.00);
insert into employee (EMPNO, ENAME, SAL)values (7499, 'ALLEN', 1980.00);
insert into employee (EMPNO, ENAME, SAL)values (7521, 'WARD', 1595.00);
insert into employee (EMPNO, ENAME, SAL)values (7566, 'JONES', 2975.00);
insert into employee (EMPNO, ENAME, SAL)values (7654, 'MARTIN', 1595.00);
insert into employee (EMPNO, ENAME, SAL)values (7698, 'BLAKE', 3245.00);
insert into employee (EMPNO, ENAME, SAL)values (7782, 'CLARK', 3260.95);
insert into employee (EMPNO, ENAME, SAL)values (7839, 'KING', 6050.00);
insert into employee (EMPNO, ENAME, SAL)values (7844, 'TURNER', 1870.00);
insert into employee (EMPNO, ENAME, SAL)values (7876, 'ADAMS', 1200.00);
insert into employee (EMPNO, ENAME, SAL)values (7900, 'JAMES', 1270.50);
insert into employee (EMPNO, ENAME, SAL)values (7902, 'FORD', 3000.00);
insert into employee (EMPNO, ENAME, SAL)values (7934, 'MILLER', 1694.00);
insert into employee (EMPNO, ENAME, SAL)values (7788, 'SCOTT', 2720.00);
-- Create table
create table SALGRADE
(
GRADE NUMBER,
LOSAL NUMBER,
HISAL NUMBER
);
insert into SALGRADE (GRADE, LOSAL, HISAL)values (1, 700, 1200);
insert into SALGRADE (GRADE, LOSAL, HISAL)values (2, 1201, 1400);
insert into SALGRADE (GRADE, LOSAL, HISAL)values (3, 1401, 2000);
insert into SALGRADE (GRADE, LOSAL, HISAL)values (4, 2001, 3000);
insert into SALGRADE (GRADE, LOSAL, HISAL)values (5, 3001, 9999);
update employee e1
set remark=(
select grade from salgrade s
where e1.sal between s.losal and s.hisal
);