从自过去三个月以来没有任何记录的数据库中选择



我需要从我的表中选择违约公司(那些自10月份以来没有注册付款的公司(

这是我的表格的一个例子:

公司id1578021-10-122021<10>22254<2021-11><11>3465<2021-12><12>4159<2022-01><1>

检查那些在2021年11月之前最后一次付款的人

drop table if exists t;
create table t(id   int,company_id  int,deposit_date    date,year   int,month int);
insert into t values
(1  ,578    ,'2021-10-12'   ,2021   ,10),
(2  ,254    ,'2021-11-17'   ,2021   ,11),
(3  ,465    ,'2021-12-15'   ,2021   ,12),
(4  ,159    ,'2022-01-12'   ,2022   ,1);
select company_id ,year*100+month
from t
group by company_id
having max(year*100+month) < 202111;

您可以使用select and where子句来过滤数据

最新更新