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 |
    +-------+--------+-----------------------------------------------------------------+-------+

  • 相关阅读:
    线程池和进程池
    初识数据库
    线程q
    event事件
    死锁和递归锁
    信号量
    PythonStudy——线程中的几种消息队列
    PythonStudy——GIL Global Interpreter Lock 全局解释器锁
    PythonStudy——异步回调
    PythonStudy——日志模块 logging
  • 原文地址:https://www.cnblogs.com/saolv/p/7390291.html
Copyright © 2011-2022 走看看