2015-03-19 90 views
0

重複顧客與我想顯示結果的30天(V_Date)顯示在30天后

所以週期內重複3個或更多相同的客戶,表看起來像

 Name  V_Date 
    Arun Kumar 2015-30-01 
    Arun Kumar 2015-31-01 
    Arun Kumar 2015-12-02 
     Vijay 2015-01-01 
     Vijay 2015-28-01 
     Vijay 2015-15-02 
     vinoth 2015-02-01 
     vinoth 2015-02-06 
     vinoth 2015-02-08 
     Anand 2015-01-01 
     Anand 2015-02-02 
     Anand 2015-03-03 

預期輸出

 Name  V_Date 
    Arun Kumar 2015-30-01 
    Arun Kumar 2015-31-01 
    Arun Kumar 2015-12-02 
     vinoth 2015-02-01 
     vinoth 2015-02-06 
     vinoth 2015-02-08 

當前能夠使用HAVING COUNT(name)> = 3選擇重複的3個或更多客戶,但無法在30天內檢查V_Date。 ?如何獲得預期的輸出...基於以下條件: -

Arun Kumar (V_Date 31-01-2015 to 12-02-2015) 
      visit (3 or more time) within 30 days 

    Vijay  (V_Date 01-01-2015 to 15-02-2015) 
      Not visit (3 or more time) within 30 days 

    Vinoth  (V_Date 01-02-2015 to 08-02-2015) 
      visit (3 or more time) within 30 days 

    Anand  (V_Date 01-01-2015 to 03-03-2015) 
      Not visit (3 or more time) within 30 days 

回答

0

只需添加WHERE語句:

.... WHERE (w.deliverydate BETWEEN (NOW() - interval '1 months')::date AND NOW()::date) 

然後使用具有聲明 如果這不是你在找什麼請更具體的