我需要從我的表格中選擇違約公司(那些自 10 月以來未注冊付款的公司)
這是我的表的示例:
| ID | company_id | 存款日期 | 年 | 月 |
|---|---|---|---|---|
| 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 |
我必須使用月份作為參考,而不是 deposit_date
任何幫助都感激不盡。提前致謝。
uj5u.com熱心網友回復:
檢查那些在 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;
uj5u.com熱心網友回復:
您可以使用 select 和 where 子句來過濾資料
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/414579.html
標籤:
