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. 中矿大新生赛 G 甄总搬石头【优先队列/哈夫曼/贪心】

    时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld 题目描述 https://www.nowcoder.com/ ...

  2. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) -B C(GCD,最长连续交替序列)

    B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input ...

  3. UVA——11988 Broken Keyboard (a.k.a. Beiju Text)

    11988 Broken Keyboard (a.k.a. Beiju Text)You’re typing a long text with a broken keyboard. Well it’s ...

  4. NIO入门之BIO

    传统BIO编程 网络编程的基本模型是Client-Server模型,也就是两个进程之间相互通信,其中服务端提供位置信息(绑定的IP地址和监听端口),客户端通过连接操作向服务端监听的端口发起连接请求,通 ...

  5. 微服务实施Spring Boot/Spring Cloud中踩过的坑(转)

    http://tietang.wang/2016/09/08/%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E5%BE%AE%E6%9C%8D%E5%8A%A1%E5%AE%9E%E6%9 ...

  6. 微博(MicroBlog)

    ylbtech_Miscellaneos  Inner 新浪微博  www.weibo.com 搜狐微博 http://t.sohu.com 网易微博 http://t.163.com/session ...

  7. Linux下自动监测并重启Apache服务脚本

    为了达到一个高可用的基于Apache的网站环境,在Apache由于种种原因自动停止运行之后,想立即恢复网站访问,这就需要有个工具实时监测Apache的运行状态并能够自动重启httpd服务,写了一个简单 ...

  8. JSONUtil.bean2Json()报Property 'key' of class has no read method. SKIPPED的问题处理

    错误警告信息描述: net.sf.json.JSONObject.defaultBeanProcessing(JSONObject.java:) Property 'handler' of class ...

  9. 深入理解dataset及其用法

    DataSet是ADO.NET的中心概念.可以把DataSet当成内存中的数据库,DataSet是不依赖于数据库的独立数据集合.所谓独立, 就是说,即使断开数据链路,或者关闭数据库,DataSet依然 ...

  10. Linux Shell常用技巧

    转载自http://www.cnblogs.com/stephen-liu74/ 一.    特殊文件: /dev/null和/dev/tty Linux系统提供了两个对Shell编程非常有用的特殊文 ...