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数据库开发常见问题及优化
- Redis-复制
- Always review
- SQLSTATE[HY000] [2003] Cant connect to MySQL server
- nginx服务器在IE下载时,apk,ipa文件变成zip的解决方法
- shell timeout
- uva 11825 Hackers&;#39; Crackdown (状压dp,子集枚举)
- CentOS6.7 用户
- qt model/view 架构基础介绍之QListWidget
- hdu 4751 Divide Groups(dfs染色 或 2-sat)
- Drying(贪心)
- 模块化写法-IIFE解析
- C++ Primer Plus 6 第二章
- Sql 的 RAISERROR用法
- java各种概念 Core Java总结
- Update API
- 使用blas做矩阵乘法
- Windows10右键添加";在此处打开命令窗口";
- mysql5.7如何修改密码以及密码如何忘记无密码登陆
- E - A Twisty Movement
热门文章
- 洛谷 P1181 数列分段Section I【贪心/最少分成多少合法的连续若干段】
- Python的功能模块[4] ->; pdb/ipdb ->; 实现 Python 的单步调试
- 大数据技术之_16_Scala学习_09_函数式编程-高级
- poj2976(01分数规划)
- MySQL注入工具sqlsus
- [LOJ6280]数列分块入门 4
- List和ArrayList的区别和联系
- iOS 设置系统音量和监听系统音量变化
- iPhone 通过UIRequiredDeviceCapabilities指定程序适用于哪些设备
- C#如何把日期转成YYYYMMDDHHMMSSFFF的精确到毫秒的格式?