去重 数据库_数据库数据怎么去重

去重 数据库_数据库数据怎么去重setnamesutf8;selectcatidfromsupe_categorieswherename=’金融’;得出catid;createtablemultmpselect*fromsupe_spaceitemswherecatidin(selectcatidfromsupe_categorieswherename=’金融’)…


Jetbrains全系列IDE稳定放心使用
set names utf8;

select catid from supe_categories where name=’金融’;

得出catid;

create table multmp select * from supe_spaceitems where catid in(select catid from supe_categories where name=’金融’); 假设上一句的出的catid为1

//以下语句是过滤重复

create table tmpa as select itemid from multmp where subject in(select subject from multmp group by subject having count(itemid)>1);

create table tmpb as select min(itemid) as itemid from multmp group by subject having count(itemid)>1;

create table tmptmp as select itemid from multmp where itemid in (select itemid from tmpa ) and itemid not in (select itemid from tmpb);//要删除的数据的itemid

delete from supe_spacenews where itemid in (select itemid from tmptmp);//删除news

delete from multmp where itemid in (select itemid from tmptmp);

drop table tmpa;

drop table tmpb;

drop table tmptmp;

delete from supe_spaceitems where catid in (select catid from supe_categories where name=’金融’); //删除原表中 catid为1的数据

insert into supe_spaceitems select * from multmp; //将过滤后的数据 添会原表

drop table multmp;//删除中间表

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/187173.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • SpringMVC工作原理(比较详细哦)「建议收藏」

    SpringMVC工作原理(比较详细哦)「建议收藏」1.用户发送请求至前端控制器DispatcherServlet(也叫中央处理器).2.DispatcherServlet收到请求调用HandlerMappering处理器映射器3.处理器映射器找到具体的处理器(可以根据xml配置、注解进行查找),生成处理器对象及处理器拦截器(如果有则生成)一并返回给DispatcherServlet.4.DispatcherServlet调用Handler…

    2022年5月15日
  • jmeter对接口进行压测_jmeter接口压测流程详解

    jmeter对接口进行压测_jmeter接口压测流程详解macjmeter压测工具的安装

    2022年10月28日
  • 解决springboot 2.0集成elasticsearch 7.6.2 查询总数为10000

    解决springboot 2.0集成elasticsearch 7.6.2 查询总数为10000小伙伴们,你们好,我是老寇据查询相关资料,在elasticsearch7.x以后的版本,当查询的结果总数大于1万时,默认total返回总数为10000在kibana获取真实总数,只需要加添加track_total_hits参数{“query”:{“match_all”:{}},”track_total_hits”:true}在springboot项目中,增加配置//获取真实总数searchSourceBuilder.trackTotalHit

    2022年5月25日
  • 看完这篇HTTP,跟面试官扯皮就没问题了

    看完这篇HTTP,跟面试官扯皮就没问题了我是一名程序员,我的主要编程语言是Java,我更是一名Web开发人员,所以我必须要了解HTTP,所以本篇文章就来带你从HTTP入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得05年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学xxx家里有网,每…

    2022年5月4日
  • Scala Json对象转Map对象[通俗易懂]

    Scala Json对象转Map对象[通俗易懂]importcom.google.gson.{JsonObject,JsonParser}importscala.collection.JavaConversions._valjsonStr=”””{“a”:1,”b”:2,”c”:3}”””valjsonObj=jsonParser.parse(jsonStr).asInstanceOf[JsonObject]valjson2map=jsonObj.entrySet.map(x=>(x.getKey,

    2022年8月23日
  • Shell脚本基础详解

    Shell脚本基础详解

    2021年6月4日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号