zoukankan      html  css  js  c++  java
  • mysql 语句 GROUP_CONCAT

    select * from blog_log;
    +----+---------------------+-------+--------+
    | id | time | level | info |
    +----+---------------------+-------+--------+
    | 1 | 2011-11-11 23:32:32 | 1 | haha |
    | 2 | 2012-12-12 12:21:21 | 1 | haha |
    | 3 | 2013-12-12 12:12:12 | 1 | hehe |
    | 4 | 2013-02-12 12:12:12 | 2 | haha |
    | 5 | 2013-12-02 12:12:12 | 2 | hehe |
    | 6 | 2013-12-02 13:12:12 | 2 | hehe |
    | 7 | 2016-12-02 12:12:12 | 2 | hehe |
    | 8 | 2013-12-25 12:12:12 | 1 | haha |
    | 9 | 2011-11-11 23:32:32 | 3 | hahage |
    | 10 | 2001-11-11 23:32:32 | 5 | hahage |
    +----+---------------------+-------+--------+

    SELECT level, info, GROUP_CONCAT(time ORDER BY time DESC SEPARATOR " | ") AS time, COUNT(1) AS count FROM blog_log GROUP BY level, info ORDER BY time DESC, count DESC
    -> ;
    +-------+--------+-----------------------------------------------------------------+-------+
    | level | info | time | count |
    +-------+--------+-----------------------------------------------------------------+-------+
    | 2 | hehe | 2016-12-02 12:12:12 | 2013-12-02 13:12:12 | 2013-12-02 12:12:12 | 3 |
    | 1 | haha | 2013-12-25 12:12:12 | 2012-12-12 12:21:21 | 2011-11-11 23:32:32 | 3 |
    | 1 | hehe | 2013-12-12 12:12:12 | 1 |
    | 2 | haha | 2013-02-12 12:12:12 | 1 |
    | 3 | hahage | 2011-11-11 23:32:32 | 1 |
    | 5 | hahage | 2001-11-11 23:32:32 | 1 |
    +-------+--------+-----------------------------------------------------------------+-------+

  • 相关阅读:
    Logwatch的配置与使用
    Redirect HTTP to HTTPS on Tomcat
    RedHat7搭建yum源服务器
    卸载RedHat7自带的yum,安装并使用网易163源
    15个Linux Yum命令实例--安装/卸载/更新
    GitHub详细教程
    RedHat7 Git 安装使用
    RedHat7 SELinux
    RedHat7配置IdM server
    IIS Shared Configuration
  • 原文地址:https://www.cnblogs.com/saolv/p/7390291.html
Copyright © 2011-2022 走看看