zoukankan      html  css  js  c++  java
  • distinct 多列详解

    1.distinct单列

    select distinct(a) from tableA;

    2.distinct多列

    select distinct a,b,c from tableA;

    注意此时是将a,b,c三列所有不同的组合全部列出来,而不仅仅只是distinct a 
    相当于以下语句:

     select a,b,c from tableA group by a,b,c

    3.另外一种的distinct多列

    其实这篇文章的最初需求如下: 
    想分别查某一张表的几个字段的distinct值

    select distinct a from tableA;
    select distinct b from tableA;
    select distinct c from tableA;

    这样是可以达到目的的。但是这样要写三条语句,不爽,想着用一条语句达到目的。 
    思考了一会,想到用union来解决这个问题。

    select distinct(a) || ' a' from tableA
    union all
    select distinct(b) || ' b' from tableA
    union all
    select distinct(c) || ' c' from tableA

    这样就达到了一条语句查询出所有结果的目的。后面拼接的字符串是为了标识这个值属于哪个字段。

  • 相关阅读:
    application , application pool., W3wp ,httpapplication, domain
    HDFS
    spark
    Hive
    container docker
    Azure&& hdinsight
    Native Code
    拥抱重构
    六个重构方法可帮你提升80%的代码质量
    重构 小步进行曲
  • 原文地址:https://www.cnblogs.com/henuyuxiang/p/7613848.html
Copyright © 2011-2022 走看看