MySQL_常用SQL语句
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语句的更多相关文章
- Mysql 常用 SQL 语句集锦
Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...
- Mysql 常用 SQL 语句集锦 转载(https://gold.xitu.io/post/584e7b298d6d81005456eb53)
Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...
- 50个常用SQL语句
50个常用SQL语句 Student(S#,Sname,Sage,Ssex) 学生表 S#学号,主键 Course(C#,Cname,T#) 课程表 C#课程号,主键 SC(S#, ...
- oracle sqlplus及常用sql语句
常用sql语句 有需求才有动力 http://blog.csdn.net/yitian20000/article/details/6256716 常用sql语句 创建表空间:create tables ...
- oracle常用SQL语句(汇总版)
Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, ...
- 常用SQL语句(增删查改、合并统计、模糊搜索)
转自:http://www.cnblogs.com/ljianhui/archive/2012/08/13/2695906.html 常用SQL语句 首行当然是最基本的增删查改啦,其中最重要的是查. ...
- oracle 常用sql语句
oracle 常用sql语句 1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom d ...
- Sqlite常用sql语句
sqlite常用sql语句 --返回UTC时间 select CURRENT_TIMESTAMP; --返回本地时间 select datetime(CURRENT_TIMESTAMP,'localt ...
- 常用SQL语句集合
一.数据定义 1.创建新数据库:CREATE DATABASE database_name2.创建新表:CREATE TABLE table_name (column_name datatype,co ...
随机推荐
- java序列化的机制与原理
有关Java对象的序列化和反序列化也算是Java基础的一部分,下面对Java序列化的机制和原理进行一些介绍. Java序列化算法透析 Serialization(序列化)是一种将对象以一连串的字节描述 ...
- Python的Web编程[0] -> Web客户端[0] -> 统一资源定位符 URL
统一资源定位符 / URL 目录 URL 构成 URL 解析 URL 处理 1 URL构成 统一资源定位符(Uniform Resource Locator) 是对可以从互联网上得到的资源的位置和访问 ...
- CocoaPods安装使用及配置私有库及注意点
如何安装? 1.安装ruby环境,添加淘宝ruby镜像 $ gem sources --remove https://rubygems.org///等有反应之后再敲入以下命令$ gem sources ...
- @selector和SEL
遇到selector发现不是很明白,网上搜到的零零星星的介绍也不成体系,索性自己翻译一下,加深一下印象.原文来自官方API文档下的Selectors. Selectors 在OC中,selector有 ...
- Android SDK 目录说明
Android SDK目录说明: AVD Manager.exe:虚拟机管理工具 SDK Manager.exe:sdk管理工具 tools目录:包括测试.调试.第三方工具.模拟器.数据管理工具等. ...
- HTTP抓包工具Fiddler
http://blog.csdn.net/kobejayandy/article/details/16908261
- C#日期格式化,时间
日期转化一 为了达到不同的显示效果有时,我们需要对时间进行转化,默认格式为:2007-01-03 14:33:34 ,要转化为其他格式,要用到DateTime.ToString的方法(String, ...
- json格式在线解析
地址:https://www.bejson.com/ { "PN": "123456", "DomainName": ".gxyc ...
- ES6中的迭代器(Iterator)和生成器(Generator)(二)
一.内建迭代器 迭代器是ES6的一个重要组成部分,在ES6中,已经默认为许多内建类型提供了内建迭代器,只有当这些内建迭代器无法实现目标时才需要自己创建.通常来说当定义自己的对象和类时才会遇到这种情况, ...
- tensorflow BasicRNNCell调试
运行以下代码,进入~/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/rnn.py和~/anaconda3/lib/python ...