用博客记录点滴……

oracle数据库语句积累

1、从一个表选出数据更新另一个表(后面的exists一定要加)

update jqhdzt
   set shid =
       (select shid
          from v_plat_userjqinfo t
         where jqhdzt.jqbh = t.JQBH
           and jqhdzt.shid <> t.SHID)
 where shid = '0000010047'
   and exists (select 1
          from v_plat_userjqinfo t
         where jqhdzt.jqbh = t.JQBH
           and jqhdzt.shid <> t.SHID)

 2、查询字段值相同的记录总数量

   1)单个字段查询

select t.name,count(1) from tuser t   having count(1)>1  group by t.name

   2)多个字段查询

SELECT t.spbh,t.spmc,t.shid,COUNT(*) FROM spxx t GROUP BY t.spbh,t.spmc,t.shid HAVING COUNT(*) > 1

 

posted @ 2016-12-15 16:40  aegisada  阅读(178)  评论(0编辑  收藏  举报