Posted on 2008-10-08 19:19
leekiang 閱讀(190)
評論(0) 編輯 收藏 所屬分類:
sql
1,批量修改明細時要判斷主單的狀態是否允許,可用exists變通解決
?
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);
2,查找某些字段重復的記錄,可先對那幾個字段分組,然后看個數,個數大于1的就說明有重復。但這樣查出的是所有重復的記錄,如果不想重復,再distinct一下
??? --如:查找stuid重復的記錄
select * from stuinfo
where stuid in (
select stuid from stuinfo
group by stuid
having(count(*))>1
)
?
參考