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

    distinct单列

    select distinct(a) from tableA

    distinct多列

    select distinct a,b,c from tableA

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

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

    另外一种的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

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

    原地址:https://www.cnblogs.com/henuyuxiang/p/7613848.html

  • 相关阅读:
    js 提升
    omnipay支付--支付宝支付
    laravel 配置sql日志
    laravel monlog配置
    php openssl相关加密解密 验签代码
    laravel validator提示信息中文化
    opendevops_codo项目研究
    Python学习笔记
    shell编程总结
    关于JeeSite开源软件
  • 原文地址:https://www.cnblogs.com/wuzx/p/14463876.html
Copyright © 2011-2022 走看看