zoukankan      html  css  js  c++  java
  • MySql显示每小时的数据

    需求显示统计前八小时用户在线数据

    select * from(
    select IFNULL(tt.c,0),d1.time from (select '2018-4-4 09:00:00' time
    union select '2018-4-4 10:00:00' time
    union select '2018-4-4 11:00:00' time
    union select '2018-4-4 12:00:00' time
    union select '2018-4-4 13:00:00' time
    union select '2018-4-4 15:00:00' time
    union select '2018-4-4 16:00:00' time
    union select '2018-4-4 17:00:00' time
    ) d1

    LEFT JOIN

    (select IFNULL(count(*),0) c,d.time from user_online uo LEFT JOIN
    (select '2018-4-4 09:00:00' time
    union select '2018-4-4 10:00:00' time
    union select '2018-4-4 11:00:00' time
    union select '2018-4-4 12:00:00' time
    union select '2018-4-4 13:00:00' time
    union select '2018-4-4 15:00:00' time
    union select '2018-4-4 16:00:00' time
    union select '2018-4-4 17:00:00' time) d on 1=1
    where (uo.online_time_start<=d.time and uo.online_time_end>=d.time) or (uo.online_time_start<=d.time and uo.online_time_end is null)
    ) tt on d1.time=tt.time)a order by a.time desc;

  • 相关阅读:
    树链剖分学习笔记(未完)
    VI 配置文件(略全)
    linux之awk
    指针之基础篇
    linux之sed
    sqlplus命令手册
    Leetcode复习: 堆和栈
    leetcode 的shell部分4道题整理
    Regular Expression Matching [leetcode]
    深入浅出JAVA
  • 原文地址:https://www.cnblogs.com/kongnengjing/p/8781094.html
Copyright © 2011-2022 走看看