1,批量修改明細(xì)時要判斷主單的狀態(tài)是否允許,可用exists變通解決
?
2,查找某些字段重復(fù)的記錄,可先對那幾個字段分組,然后看個數(shù),個數(shù)大于1的就說明有重復(fù)。但這樣查出的是所有重復(fù)的記錄,如果不想重復(fù),再distinct一下
??? --如:查找stuid重復(fù)的記錄
select * from stuinfo
where stuid in (
select stuid from stuinfo
group by stuid
having(count(*))>1
)
? 參考
?
update TB_DETAIL d
??????? set d.flag= 1,
?????????? d.enabletime=sysdate
????? where d.testfield='AAA' and
exists (select *
?????????????? from TB_DETAIL tempd
?????????????? left join TB_MAIN m on tempd.mainid = m.mainid
????????????? where m.status = 'true'
??????????????? and tempd.detailid = d.detailid);
??? --如:查找stuid重復(fù)的記錄
select * from stuinfo
where stuid in (
select stuid from stuinfo
group by stuid
having(count(*))>1
)
? 參考