mysql gmt create_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';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值