標籤:strong where select format sch 同比 相同 mon 大小
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語句