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

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

  • 相关阅读:
    通过 Web 服务共享 Windows 剪贴板
    bzoj 1007[HNOI2008]水平可见直线 半平面交
    c#读写INI
    c#获得伪静态页码
    c#判断部分
    c#网络通信
    C# 转换函数
    c#文件操作
    c#进制转换
    服务器端异步接受SOKCET请求
  • 原文地址:https://www.cnblogs.com/henuyuxiang/p/7613848.html
Copyright © 2011-2022 走看看