Loading

【SQL】区分新来顾客和再访顾客

-- 赋值 客户来访记录
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

 

posted @ 2013-12-08 14:02  uzipi  阅读(641)  评论(0编辑  收藏  举报