-- 赋值 客户来访记录 SELECT m.* FROM (SELECT x.*, CASE WHEN x.ts > (SELECT MIN(a.ts) FROM USER.ps_afterrecord a WHERE a.pk_customer = x.pk_customer) THEN 1 -- 再访客 ELSE 0 -- 新客 END AS isold FROM USER.ps_afterrecord x) m WHERE m.isold =1 AND nvl(m.dr,0)=0
-- 赋值 客户来访记录 SELECT m.* FROM (SELECT x.*, CASE WHEN x.ts > (SELECT MIN(a.ts) FROM USER.ps_afterrecord a WHERE a.pk_customer = x.pk_customer) THEN 1 -- 再访客 ELSE 0 -- 新客 END AS isold FROM USER.ps_afterrecord x) m WHERE m.isold =1 AND nvl(m.dr,0)=0