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
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    代码操作
    购物车
    利息计算器
    生成海报
    知识库
    JavaScript处理字符串--参照W3C
    C#输入排序-冒泡
    enum举例
    C# 表达式计算器----数据结构
    C# 测试单词的完美度
  • 原文地址:https://www.cnblogs.com/seniortestingdev/p/2556375.html
Copyright © 2011-2022 走看看