avatar

sql查询语句

按年分组统计

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 表名;
文章作者: 123
文章链接: https://gao5805123.github.io/123/2020/07/29/sql%E8%AF%AD%E5%8F%A5/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 123
打赏
  • 微信
    微信
  • 支付宝
    支付宝