![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I was able to solve the following problem using PL/SQL. However I would like to know if it can be solved using a SQL query: The table has these columns: user_id, purchase_date I would like to count the number of store visits by a person within a calendar year. Purchase_dates within a rolling 7 day period are counted as one store visit. There can be several or no purchases within these 7 days. Next purchase date can start any time. For example: Purchase_Date: 11/1/2005, 11/3/2005, 11/11/2005, 12/1/2005, 12/5/2005, 12/18/2005 Number of Visits = 4 11/1/2005 and 11/3/2005 count as one visit 11/11/2005 counts as one visit 12/1/2005 and 12/5/2005 count as one visit 12/18/2005 counts as one visit Thanks in advance. Nick Li |
#3
| |||
| |||
|
|
| 12/1/2005 and 12/5/2005 count as one visit | 12/18/2005 counts as one visit |
|
"nickli" <ningli2000 (AT) hotmail (DOT) com> a écrit dans le message de news: 1134517017.107449.295790 (AT) g14g20...oglegroups.com... | Hi, | | I was able to solve the following problem using PL/SQL. However I | would like to know if it can be solved using a SQL query: | | The table has these columns: user_id, purchase_date | I would like to count the number of store visits by a person | within a calendar year. Purchase_dates within a rolling 7 day period | are counted as one store visit. There can be several or no purchases | within these 7 days. Next purchase date can start any time. For | example: | | Purchase_Date: 11/1/2005, 11/3/2005, 11/11/2005, 12/1/2005, | 12/5/2005, 12/18/2005 | Number of Visits = 4 | 11/1/2005 and 11/3/2005 count as one visit | 11/11/2005 counts as one visit | 12/1/2005 and 12/5/2005 count as one visit | 12/18/2005 counts as one visit | | Thanks in advance. | | Nick Li | What should be the result if there was a visit at 11/08/2005 or 11/09/2005? Regards Michel Cadot |
#4
| |||
| |||
|
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Thanks for your prompt reply. I tried your solution on the following dates: 10/5/1996, 10/6/1996, 10/10/1996 The results I got is 2 visits, which should be 1 visit instead, since 10/5/1996 to 10/10/1996 falls within one rolling 7 day period. Thanks. Nick |
#7
| |||
| |||
|
|
Hi, I was able to solve the following problem using PL/SQL. However I would like to know if it can be solved using a SQL query: The table has these columns: user_id, purchase_date I would like to count the number of store visits by a person within a calendar year. Purchase_dates within a rolling 7 day period are counted as one store visit. There can be several or no purchases within these 7 days. Next purchase date can start any time. For example: Purchase_Date: 11/1/2005, 11/3/2005, 11/11/2005, 12/1/2005, 12/5/2005, 12/18/2005 Number of Visits = 4 11/1/2005 and 11/3/2005 count as one visit 11/11/2005 counts as one visit 12/1/2005 and 12/5/2005 count as one visit 12/18/2005 counts as one visit Thanks in advance. Nick Li |
#8
| |||
| |||
|
#9
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |