我有两个表claims
,其中有ptid,date_entered(date),以及customer_details
,其中有ptid,first_transaction_date(varchar)。 claims
表中输入的date_date的格式为YYYY-MM-DD,而customer_details
表中输入的first_transaction_date的格式为YYYYMM。
目标:对于索赔表中所有唯一的ptid,我想查找first_transaction_date和date_entered天数之间的差异。我想看看在进入奖励计划两年之前,系统中已有什么客户。
我在以下方面遇到问题: 1.不同的数据类型 2.格式上的差异
这就是我所拥有的:
drop table if exists claims_1;
select a.*,b.diag_min,diag_min - first_month_active::date as start_dif
into claims_1
from claims as a
left join customer_details as b on a.ptid = b.ptid
where start_dif >= 0 and end_dif >= 0;
当我尝试使用str_to_date转换数据类型时,出现此错误:
(500310)无效的操作:函数str_to_date(字符变化,“未知”)不存在;
select date_format(str_to_date(first_month_active,'%Y%m'),'%Y-%m')from customer_details