分享java帶來的快樂

          我喜歡java新東西

          刪除部分重復(fù)字段的記錄

          創(chuàng)建臨時表
          create table tmp_dur as
          select a.shop_id,a.city_id,a.product_id,max(a.id) as mid from 51fanli_tuandh_item as a group by a.shop_id,a.city_id,a.product_id having count(*) > 1

          查詢聯(lián)合表
          SELECT a.shop_id,a.city_id,a.product_id from tmp_dur a , 51fanli_tuandh_item b where a.shop_id = b.shop_id and a.city_id = b.city_id and a.product_id = b.product_id

          刪除重復(fù)項目
          delete from 51fanli_tuandh_item
          where 51fanli_tuandh_item.id != (
          SELECT b.mid from tmp_dur b
          where 51fanli_tuandh_item.city_id = b.city_id and 51fanli_tuandh_item.shop_id = b.shop_id and 51fanli_tuandh_item.product_id = b.product_id
          );

          刪除臨時表
          drop tmp_dur;

          添加唯一
          ALTER TABLE  `51fanli_tuandh_item` ADD UNIQUE (
          `shop_id` ,
          `city_id` ,
          `product_id`
          );

          posted on 2011-08-29 17:32 強強 閱讀(426) 評論(0)  編輯  收藏 所屬分類: mysql

          主站蜘蛛池模板: 福泉市| 穆棱市| 铁岭县| 广丰县| 开鲁县| 阳西县| 西青区| 舒兰市| 江永县| 老河口市| 安西县| 盐山县| 西盟| 海晏县| 辛集市| 买车| 冀州市| 寿阳县| 布尔津县| 墨玉县| 旺苍县| 淮南市| 巍山| 宝兴县| 白朗县| 泰来县| 雅安市| 铁力市| 南溪县| 松江区| 靖西县| 休宁县| 金昌市| 济南市| 灌阳县| 垫江县| 泽库县| 西盟| 焦作市| 正安县| 万州区|