按年分组统计

1
select date_format(列名, '%Y') `year`, COUNT(*) count from 表名 group by date_format(列名, '%Y');

按月分组统计

1
select date_format(列名, '%Y-%m') `month`, COUNT(*) count from 表名 group by date_format(列名, '%Y-%m');

按天分组统计

1
select date_format(列名, '%Y-%m-%d') `day`, COUNT(*) count from 表名 group by date_format(列名, '%Y-%m-%d');

获取表的字段数据类型、字段名称、能否为空和注释信息

1
select distinct data_type, column_name, is_nullable, column_comment from information_schema.columns where table_name = '表名'

获取表的所有信息

1
select distinct * from information_schema.columns where table_name = '表名'

替换字段中符合条件的数据替换为自定字段

1
select (case 字段名 when '字段中的数据' then '要替换成的字段' when '' then '' ... end) from 表名;