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这个表 想问问 我应该怎么写呢? 谢谢了
解决方案 »
- 新手求助
- 请教:我安装的oracle10.2怎么没有SQL Load的DEMO?谢谢。
- 请教一个数据库设计问题
- pdf的文件,放入数据库中,然后通过网页进行全文检索,如何实现呢
- 那为高手知道‘ora-02064 不支持分布式操作’如何解决阿!
- 关于ORACLE联表查询的一个问题(有个字段是带有多个数据的),急~~~~~~
- proc编写的代码预编译后生成c文件,用gcc编译报错!(急,高手请进)
- 如何增加一个在SQL PLUS中可以登陆的用户,急?
- oracleDBA宝典(PDF)哪里有下载??
- 高分求个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)