Posted on 2008-10-08 19:19
leekiang 阅读(187)
评论(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
)
参考