常用场景SQL

求所在月份的数据都处理完成

  • 按月份查出该月的总数量 num1
  • 按月份查出该月都处理完成的数量 num2
  • 比较 num1 = num2 代表处理完成
select * from
(
	select count(1) as num, month from table1 group by month
) A
left join
(
	select count(1) as num, month from table1 WHERE STATUS = 1 group by month
) B ON A.month = B.month
where a.num = b.num

查询表结构

-- 查询表
select distinct t.TABLE_SCHEMA ,t.TABLE_NAME as 表名, t.TABLE_COMMENT as 表描述, 
t.TABLE_ROWS 数据条数, concat(round(t.DATA_LENGTH/1024/1024,2),'M') as 数据大小
from information_schema.tables t
where t.TABLE_SCHEMA = 'dhcs'
-- AND t.TABLE_NAME like '%log%' 
-- AND T.TABLE_COMMENT LIKE '%日志表%'
ORDER BY t.TABLE_NAME,t.TABLE_ROWS desc, t.CREATE_TIME desc;

-- 查询字段
select distinct t.TABLE_SCHEMA,t.TABLE_NAME,t.IS_NULLABLE,LOWER(t.COLUMN_NAME), t.COLUMN_NAME,t.COLUMN_TYPE,t.COLUMN_COMMENT 
from information_schema.columns t 
where t.TABLE_SCHEMA = 'dhcs'
-- and table_name like '%order%'
-- and COLUMN_COMMENT like '%订单表%'
-- and LOWER(t.COLUMN_NAME) like '%orderno%'
ORDER BY TABLE_NAME;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值