UPDATE t_name t1
SET t1.t_name.status = t2.status
WHERE exists
(select t2.id from (select c.id , a.status from t_seae a,t_name c where c.id = a.id and c.status = '考试 ' and a.time is not null and a.time = (select max(b.time) from t_seae b where a.id=b.id ) ) t2 where t1.id=t2.id);
其实就是想用 一个表中字段的值 去更新 别一个表中字段的值 想是这么写 但 SET t1.t_name.status = t2.status 这里不认t2这个表 想问问 我应该怎么写呢? 谢谢了
SET t1.t_name.status = t2.status
WHERE exists
(select t2.id from (select c.id , a.status from t_seae a,t_name c where c.id = a.id and c.status = '考试 ' and a.time is not null and a.time = (select max(b.time) from t_seae b where a.id=b.id ) ) t2 where t1.id=t2.id);
其实就是想用 一个表中字段的值 去更新 别一个表中字段的值 想是这么写 但 SET t1.t_name.status = t2.status 这里不认t2这个表 想问问 我应该怎么写呢? 谢谢了
解决方案 »
- oracle 怎么在同一个数据库里把一张表的数据插入另一张表
- select name from student和select name from student where name='%%' 的区别?
- 用plsql如何备份 大字段 clob字段呢?
- 谁给个oracle游标读记录然后操作这些记录再返回这些记录的例子
- 在 Linux 下构建以自然周作为备份周期的完备的 Oralce 数据库备份系统
- 关于ORACLE 9i的外联接,到底现在是什么标准?
- 如何在PL/SQL中使用动态SELECT的游标?
- 请问:sqlserver数据怎样导入ora数据库?
- ===求存储过程,关于事务处理===
- 如果procedure中执行的是一条SQL语句,如何得到返回的数据集?
- 一段触发器的代码,有些地方不明白请大家请教下
- Oracle ODAC 连接 Oracle RAC(Delphi)
set t1.t_name.status=(select status from (select t2.status from t_seae t2 where t2.id=t1.id and t2.time is not null order by time desc) where rownum=1)
where t1.status='考试';
说明:
1.用了8分心思,没有实机测试返回的结果集是否满足楼主要求
2.status='考试'这个条件提到最外面是因为:原sql中c表与t1表是同一张表,这样写大幅提高性能。
3.使用了rownum伪列,减少了访问次数,大幅提高了性能。
SET t1.t_name.status = (select t2.status from
(select c.id , a.status from t_seae a,t_name c
where c.id = a.id and c.status = '考试 '
and a.time is not null and a.time =
(select max(b.time) from t_seae b where a.id=b.id ) ) t2 whre t1.id=t2.id)where exists
(select 'a' from (select c.id , a.status from t_seae a,t_name c
where c.id = a.id and c.status = '考试 '
and a.time is not null and a.time =
(select max(b.time) from t_seae b where a.id=b.id ) ) tt where t1.id=tt.id)