update table_a set latesttm = u.tm, latestdata = u.data from
(select * from table_b inner join
( select max(tm) newesttm from table_b group by stcd
)v on drp.tm = v.newesttm
) u where table_a.id = u.id
a表中假如有三個id物件,latesttm,latestdata表示三個物件最新時刻的最新狀態資訊,其值是由b表中檢索更新而來,b表中不斷增加的是三個id物件的最新狀態和對應的時刻,通過檢索b表中每個id物件最新時刻的最新資料資訊去更新a表。
update [dealers] set dianjilv = b.dianji from
(select count(dealerid) as dianji,dealerid
from [tongjidealerphoneclick]
group by dealerid
) as b
where id=b.dealerid
用乙個表的記錄更新另外乙個表
用table 1的address,phone number更新table 2的address,phone number,注意 1.set 後面加上要更新的列,有多個要更新的列時,加上多個列,2.where 後面加上table 1和table 2的關聯列,有多個關聯列時,加上多個列 3.rownum用...
Oracle根據乙個表更新另乙個表的幾種寫法
1.declare cursor t1 is select from tablename begin for rec in t1 loop update tablename t set t.detail rec.jieshao where t.objectid rec.objid end loop ...
儲存過程 根據乙個表對另乙個表進行更新
編寫mysql儲存過程,通過查詢乙個表中資料,更新到另外乙個表中 舉例來說,存在兩張表roledata,scoreinfo,下面儲存過程,通過游標,遍歷查詢scoreinfo表中scroe的值來更新表roledata中的role scroe值 drop procedure if exists pro...