分享java帶來的快樂

          我喜歡java新東西

          刪除部分重復字段的記錄

          創建臨時表
          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

          查詢聯合表
          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

          刪除重復項目
          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

          主站蜘蛛池模板: 马关县| 延吉市| 蒙自县| 邵东县| 竹山县| 平和县| 普安县| 太谷县| 阳西县| 叶城县| 平阴县| 内乡县| 夏邑县| 雅江县| 潮安县| 长葛市| 浦东新区| 建昌县| 温泉县| 曲水县| 如东县| 太仆寺旗| 商洛市| 台前县| 沿河| 清远市| 长子县| 乐至县| 哈尔滨市| 香格里拉县| 新平| 信宜市| 格尔木市| 永胜县| 禹城市| 嘉禾县| 什邡市| 云南省| 昌江| 玉门市| 汾西县|