1、按小时统计的语句

    select
    concat(date_format(gmt_create, "%Y-%m-%d %k:00~"), hour(gmt_create)+1, ":00") as 'time',
    count(*) as num
    from t_order
    where gmt_create>='2016-03-06 00:00:00' and gmt_create<='2016-03-06 23:59:59'
    group by left(gmt_create, 13);

    select
    concat(date_format(gmt_create, "%Y-%m-%d %k:00~"), hour(gmt_create)+1, ":00") as 'time',
    count(*) as num
    from t_order
    where gmt_create>='2016-03-06 00:00:00' and gmt_create<='2016-03-06 23:59:59'
    group by date_format(a.gmt_create,'%Y-%m-%d %H:00');

  2、加上序号
    select
    (@rowNO := @rowNo+1) as rowno,
    concat(date_format(a.gmt_create, "%Y-%m-%d %k:00~"), hour(a.gmt_create)+1, ":00") as 'time',
    count(*) as num
    from t_order a,(select @rowNO :=0) b
    where a.gmt_create>='2016-03-06 00:00:00' and a.gmt_create<='2016-03-06 23:59:59'
    group by date_format(a.gmt_create,'%Y-%m-%d %H:00');

  3、环比,就是相邻时间段的对比。如:14年4月和14年3月是相邻时间段,这两个时间段的数据对比,就是环比。
    select date_format(a.m_adddate,'%Y-%m') as 时间, count(*) as `当月`,
    (select count(*) from job_myreceive where date_format(a.m_adddate,'%Y%m') = date_format(date_add(m_adddate,interval 1 month),'%Y%m')) as 上月
    from job_myreceive a group by 1

  4、同比,是指在相邻时段中的某一相同时间点进行比较。
    如:13年和14年是相邻时段,13年3月和14年3月是这两个相邻时段的同一个时间点,都是3月,这两个时段进行数据对比,就是同比。

  5、查看数据库的大小,结果是以字节为单位,除1024为K,除1048576为M。
    select TABLE_SCHEMA '数据库名',(sum(DATA_LENGTH)+sum(INDEX_LENGTH))/1048576 '大小(M)' from information_schema.tables where TABLE_SCHEMA='xiancheng';

  6、查看表的大小,结果是以字节为单位,除1024为K,除1048576为M。
    select TABLE_NAME '表名',(DATA_LENGTH+INDEX_LENGTH)/1048576 '大小(M)' from information_schema.tables where TABLE_SCHEMA='xiancheng';

MySQL_常用SQL语句的更多相关文章

  1. Mysql 常用 SQL 语句集锦

    Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...

  2. Mysql 常用 SQL 语句集锦 转载(https://gold.xitu.io/post/584e7b298d6d81005456eb53)

    Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...

  3. 50个常用SQL语句

    50个常用SQL语句 Student(S#,Sname,Sage,Ssex) 学生表  S#学号,主键 Course(C#,Cname,T#) 课程表          C#课程号,主键 SC(S#, ...

  4. oracle sqlplus及常用sql语句

    常用sql语句 有需求才有动力 http://blog.csdn.net/yitian20000/article/details/6256716 常用sql语句 创建表空间:create tables ...

  5. oracle常用SQL语句(汇总版)

    Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, ...

  6. 常用SQL语句(增删查改、合并统计、模糊搜索)

    转自:http://www.cnblogs.com/ljianhui/archive/2012/08/13/2695906.html 常用SQL语句 首行当然是最基本的增删查改啦,其中最重要的是查. ...

  7. oracle 常用sql语句

    oracle 常用sql语句 1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom d ...

  8. Sqlite常用sql语句

    sqlite常用sql语句 --返回UTC时间 select CURRENT_TIMESTAMP; --返回本地时间 select datetime(CURRENT_TIMESTAMP,'localt ...

  9. 常用SQL语句集合

    一.数据定义 1.创建新数据库:CREATE DATABASE database_name2.创建新表:CREATE TABLE table_name (column_name datatype,co ...

随机推荐

  1. HDU 5915 The Fastest Runner Ms. Zhang (CCPC2016 长春 E题,分类讨论 + 求字典序最小的直径 + 数据结构寻找最小值)

    题目链接  CCPC2016 Changchun Problem E 题意  给定一个$n$个点$n$条边的无向图,现在从某一点$s$出发,每个点都经过一遍,最后在$t$点停止,经过的边数为$l$   ...

  2. HDU 6395 2018 Multi-University Training Contest 7 (快速幂+分块)

    原题地址 Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  3. 理解竞争条件( Race condition)漏洞

    这几天一个叫做"Dirty COW"的linux内核竞争条件漏洞蛮火的,相关公司不但给这个漏洞起了个洋气的名字,还给它设计了logo(见下图),首页,Twitter账号以及网店.恰 ...

  4. shell 查找目录

    查找目录:find /(查找范围) -name '查找关键字' -type d

  5. Codeforces E. Bash Plays with Functions(积性函数DP)

    链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...

  6. 【poj2155】【Matrix】二位树状数组

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=34310873 Description Given ...

  7. thinkphp3.0增加setInc、setDec方法

    thinkphp3.0增加setInc.setDec方法 thinkphp3.0增加setInc.setDec方法,今天查看thinkphp2.0的方法setInc.setDec时是这样写的: 而对于 ...

  8. 获取本机IP,用户代理

    1.获取本机IP:http://httpbin.org/ip 2.获取用户代理 https://httpbin.org/user-agent https://httpbin.org/ httpbin( ...

  9. java 过滤器(Filter)与springMVC 拦截器(interceptor)的实现案例

    java 过滤器Filter: package com.sun.test.aircraft.filter;import javax.servlet.*;import java.io.IOExcepti ...

  10. NativeCode中通过JNI反射调用Java层的代码,以获取IMEI为例

    简单说,就是在NativeCode中做一些正常情况下可以在Java code中做的事儿,比如获取IMEI. 这种做法会使得静态分析Java层代码的方法失效. JNIEXPORT jstring JNI ...