mysql生成摘要的命令实例

发布时间:2019-12-23编辑:脚本学堂
mysql数据库如何生成摘要信息,使用mysql count函数生成摘要的sql语句实例,供大家学习参考。

mysql生成摘要
 

select * from states order by name;

使用count函数生成摘要---
 

复制代码 代码示例:

select count(*) from driver_log;
select count(*) from states;

select table_rows
from information_schema.tables
where table_schema = 'cookbook'
and table_name = 'states';

show tables status;

select count(*) from driver_log where miles > 200;
select count(*) from driver_log where name = 'Suzi';
select count(*) from states where statehood < '1900-01-01';
select count(*) from states where statehood between '1800-01-01' and '1899-12-31';

select count(if(dayofweek(trav_date)=7, 1, null)) as 'Staturday trips',
count(if(dayofweek(trav_date)=1, 1, null)) as 'Sunday trips'
from driver_log;

select count(if(dayofweek(trav_date) in (1, 7), 1, null)) as 'weekend trips',
count(if(dayofweek(trav_date) in (1, 7), null, 1)) as 'weekday trips'
from driver_log;

create view trip_summary_view as
select count(if(dayofweek(trav_date) in (1, 7), 1, null)) as 'weekend trips',
count(if(dayofweek(trav_date) in (1, 7), null, 1)) as 'weekday trips'
from driver_log;

select * from trip_summary_view;