我使用Oracle 11g数据库,并有两个表:SQL更新查询具体情况
EMP
ID EMPNO AGE DATE_PUBLISHED
1 1001 11 14/01/1999
2 1002 22 14/01/1999
3 1003 33 14/01/1999
4 1004 44 14/01/1999
5 1005 55 14/01/1999
6 1006 66 14/01/1999
EMP_MIRROR
ID EMPNO AGE DATE_PUBLISHED
1 1001 11 05/01/2004
2 1123 54 05/01/2004
3 1003 87 05/01/2004
4 1004 65 05/01/2004
5 1545 78 05/01/2004
6 1006 14 05/01/2004
我想更新DATE_PUBLISHED
专栏基于以下条件210表:
如果在两个表的任何ID
,存在的EMPNO
或AGE
的值的差,那么EMP_MIRROR
的DATE_PUBLISHED
柱应该被更新为SYSDATE
。
EMP_MIRROR (after updation)
ID EMPNO AGE DATE_PUBLISHED
1 1001 11 05/01/2004
2 1123 54 07/07/2014
3 1003 87 07/07/2014
4 1004 65 07/07/2014
5 1545 78 07/07/2014
6 1006 14 07/07/2014
结果集说明:
ID: 1 (EMPNO and AGE are same in both the tables, hence DATE_PUBLISHED is not updated)
ID: 2 (EMPNO and AGE are different in both the tables, hence DATE_PUBLISHED is updated)
ID: 3 (AGE is different in both the tables, hence DATE_PUBLISHED is updated)
ID: 4 (AGE is different in both the tables, hence DATE_PUBLISHED is updated)
ID: 5 (EMPNO and AGE are different in both the tables, hence DATE_PUBLISHED is updated)
ID: 6 (AGE is different in both the tables, hence DATE_PUBLISHED is updated)
请建议的查询可以达到这个效果。
的数据库您使用像这样的东西? –
鉴于你引用SYSDATE,我假设oracle,请添加此标签。 –
Oracle 11g数据库 –