2015-03-19 86 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) 

然后使用具有声明 如果这不是你在找什么请更具体的