guanxf

          我的博客:http://blog.sina.com.cn/17learning

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            71 隨筆 :: 1 文章 :: 41 評論 :: 0 Trackbacks
          <2015年3月>
          22232425262728
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          bolg

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          1、多表級聯刪除:
          ---DELETE---
          DELETE from a_msg_push,a_announcement
          using a_msg_push,a_announcement
          where  a_msg_push.announcement_id=a_announcement.id and a_announcement.Create_time<'2014-11-19 23:59:59';

          2、子查詢刪除:
          -----------delete--------
          DELETE From  t_repeat  where t_repeat.id in(
          SELECT tb.id from (
          SELECT *  from t_repeat   t 
          where 
          1=1
          and 
          (t.cid,t.uid ) in (select t1.cid,t1.uid from t_repeat t1 group by t1.cid,t1.uid having count(*) > 1) 
          and 
          t.id  not in (select min(t2.id) from t_repeat t2 group by t2.cid,t2.uid having count(*)>1) 
          ) as tb )

          3、子表刪除:
          -----------delete--------
          DELETE From  t_repeat  where t_repeat.id  not in
             SELECT tb.id from(
          select  a.id from t_repeat a where a.id =(
          select   max(b.id) from t_repeat b where a.cid=b.cid and a.uid=b.uid
             )as tb
          )
          posted on 2015-03-01 22:52 管先飛 閱讀(2557) 評論(0)  編輯  收藏 所屬分類: Database
          主站蜘蛛池模板: 临潭县| 长沙县| 晋城| 涟水县| 芦溪县| 莲花县| 井陉县| 定安县| 余庆县| 图木舒克市| 涞源县| 抚州市| 耒阳市| 阿荣旗| 贵溪市| 遂平县| 宁都县| 衡阳县| 桐柏县| 横峰县| 泰来县| 德州市| 永定县| 泰顺县| 苏尼特右旗| 晋宁县| 海林市| 贺兰县| 微山县| 南皮县| 五家渠市| 景洪市| 开化县| 汉沽区| 巴青县| 诸暨市| 津市市| 青神县| 高平市| 黑河市| 海城市|