zoukankan      html  css  js  c++  java
  • oracle去重复记录的方式不用distinct而用groupby

    http://chenxy.blog.51cto.com/729966/728112,

    参考文档二:http://topic.csdn.net/u/20080508/10/4b56808e-ab77-4d6e-8e75-47f281e8e33c.html

    例如下面的sql语句:

    单个字段去掉重复:

    select pp.p_product_id,
           pp.product_name,
           pp.product_level_name,
           ud.depart_path_name,
           pp.recommand_level,
           pp.product_type,
           pp.travelline_type,
           pp.departure,
           pp.destination,
           pp.sale_city_codes,
           pp.travel_day_span,
           pp.valid,
           pp.modify_datetime
      from p_product pp ,u_department ud where pp.u_department_id=ud.department_id  
      and pp.u_department_id in(select us.u_department_id from p_product us group by us.u_department_id having count(*)>1)
      order by pp.modify_datetime desc;
     
    多个字段去掉重复:
     
    select pp.p_product_id,
           pp.product_name,
           pp.product_level_name,
           ud.depart_path_name,
           pp.recommand_level,
           pp.product_type,
           pp.travelline_type,
           pp.departure,
           pp.destination,
           pp.sale_city_codes,
           pp.travel_day_span,
           pp.valid,
           pp.modify_datetime
      from p_product pp ,u_department ud where pp.u_department_id=ud.department_id  
      and (pp.u_department_id,ud.depart_path_name)in(select us.u_department_id,ud.depart_path_name from p_product us,u_department ud group by us.u_department_id,ud.depart_path_name having count(*)>1)
      order by pp.modify_datetime desc;

    最好不使用disctinct


    作者:高级测试开发网
    博客地址:https://seniortesting.club
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    15 反转链表
    八大排序算法总结(2)
    八大排序算法总结(1)
    22从上往下打印二叉树
    19顺时针打印矩阵
    20包含min函数的栈
    SpringMVC-Mybatis整合和注解开发
    优雅的代码之选择不同支付方式
    利用freemarker+SAX解析xml的方式对excel文件字段校验
    pl/sql编程语言
  • 原文地址:https://www.cnblogs.com/seniortestingdev/p/2556375.html
Copyright © 2011-2022 走看看