SELECT DISTINCT(MON.ID),MON.RATIO
FROM BAS_F MON,BAS_O SEL
WHERE MON.STATUS = 'N'
AND SEL.STATUS = 'N'
AND SEL.ID = MON.ID
怎么把筛选出来的数据更新到另一个表TRD_HIST中,他们三个表有个共同的字段ID
------解决思路----------------------
update TRD_HIST set RATIO=(select MAX(MON.RATIO)
FROM BAS_F MON,BAS_O SEL
WHERE MON.STATUS = 'N'
AND SEL.STATUS = 'N'
AND SEL.ID = MON.ID
and MON.ID=TRD_HIST.ID)
WHERE EXISTS(select 1
FROM BAS_F MON,BAS_O SEL
WHERE MON.STATUS = 'N'
AND SEL.STATUS = 'N'
AND SEL.ID = MON.ID
and MON.ID=TRD_HIST.ID)
------解决思路----------------------
加min的作用是为了防止子查询返回多条记录
UPDATE TRD_HIST T
SET T.RATIO =
(SELECT MIN(MON.RATIO)
FROM BAS_F MON, BAS_O SEL
WHERE MON.STATUS = 'N'
AND SEL.STATUS = 'N'
AND SEL.ID = MON.ID
AND T.ID = MON.ID);