• MySQL 里面的Where 和Having和Count 和distinct和Group By对比


    mysql> select accid as uid,date(datetime) AS datetime from game.logLogin GROUP BY accid HAVING datetime='2013-8-20';
    +---------+------------+
    | uid     | datetime   |
    +---------+------------+
    | 1000010 | 2013-08-20 |
    | 1000012 | 2013-08-20 |
    +---------+------------+
    2 rows in set (0.00 sec)

    而实际的例子是

    mysql> select accid as uid,date(datetime) AS datetime from game.logLogin HAVING datetime='2013-8-20';
    +---------+------------+
    | uid     | datetime   |
    +---------+------------+
    | 1000004 | 2013-08-20 |
    | 1000004 | 2013-08-20 |
    | 1000001 | 2013-08-20 |
    | 1000000 | 2013-08-20 |
    | 1000004 | 2013-08-20 |
    | 1000004 | 2013-08-20 |
    | 1000012 | 2013-08-20 |
    | 1000010 | 2013-08-20 |
    | 1000000 | 2013-08-20 |
    | 1000002 | 2013-08-20 |
    | 1000006 | 2013-08-20 |
    | 1000003 | 2013-08-20 |
    | 1000003 | 2013-08-20 |
    | 1000012 | 2013-08-20 |
    | 1000003 | 2013-08-20 |
    |       0 | 2013-08-20 |
    | 1000012 | 2013-08-20 |
    +---------+------------+
    17 rows in set (0.00 sec)

    用大腿想都会不对

    mysql> select distinct accid as uid from (select accid,date(datetime) AS datetime from game.logLogin HAVING datetime='2013-8-20') as t;
    +---------+
    | uid     |
    +---------+
    | 1000004 |
    | 1000001 |
    | 1000000 |
    | 1000012 |
    | 1000010 |
    | 1000002 |
    | 1000006 |
    | 1000003 |
    |       0 |
    +---------+
    9 rows in set (0.00 sec)

    当然如何不用 HAVING 和 DISTINCT 和 COUNT 还有GROUP By 的话是可以找出记录的

    mysql> select accountID as uid,date(signTime) AS signTime from platform.account HAVING signTime='2013-8-20';
    +---------+------------+
    | uid     | signTime   |
    +---------+------------+
    | 1000013 | 2013-08-20 |
    | 1000014 | 2013-08-20 |
    +---------+------------+
    2 rows in set (0.00 sec)
    
    mysql> select accountID as uid,date(signTime) AS signTime from platform.account HAVING signTime='2013-8-19';
    +---------+------------+
    | uid     | signTime   |
    +---------+------------+
    | 1000000 | 2013-08-19 |
    | 1000001 | 2013-08-19 |
    | 1000002 | 2013-08-19 |
    | 1000003 | 2013-08-19 |
    | 1000004 | 2013-08-19 |
    | 1000005 | 2013-08-19 |
    | 1000006 | 2013-08-19 |
    | 1000007 | 2013-08-19 |
    | 1000008 | 2013-08-19 |
    | 1000009 | 2013-08-19 |
    | 1000010 | 2013-08-19 |
    | 1000011 | 2013-08-19 |
    | 1000012 | 2013-08-19 |
    +---------+------------+
    13 rows in set (0.00 sec)
  • 相关阅读:
    iis应用程序池定时自动回收
    js获取1100之间的随机整数
    一个简单的方法实现ASP.NET网站实现http访问强制转https(不需要URL Rewrite)
    js 生成的html class属性失效问题
    此网站无法提供安全连接(客户端和服务器不支持一般 SSL 协议版本或加密套件。)TLS 1.1/TLS 1.2配置
    nextcloud & aria2 搭建 芒果
    AndroidStudio开发Flutter使用技巧
    Jenkins配置gitlab合并分支后自动构建
    Python 中 import module 和 package 方法简单记录
    https域名证书cer转pem格式
  • 原文地址:https://www.cnblogs.com/jackluo/p/3269978.html
Copyright © 2020-2023  润新知