I have the following definition of a table with sample data. In the following table, product and customer date are key fields.
Table One Customer Product Date SALE XA 01/01/2010 YES XA 02/01/2010 YES XA 03/01/2010 NO XA 04/01/2010 NO XA 05/01/2010 YES XA 06/01/2010 NO XA 07/01/2010 NO XA 08/01/2010 NO XA 09/01/2010 YES XA 10/01/2010 YES XA 11/01/2010 NO XA 12/01/2010 YES
In the above table, I need to find N or> N consecutive records where there was no sale, the sale value was "NO", For example, if N is 2, the result set will return the following
Customer Product Date SALE XA 03/01/2010 NO XA 04/01/2010 NO XA 06/01/2010 NO XA 07/01/2010 NO XA 08/01/2010 NO
Can someone help me with a SQL query to get the desired results. I am using SQL Server 2005. I started playing using the ROW_NUMBER () AND PARTITION clauses, but no luck. Thanks for any help
sql sql-server-2005
user320587
source share