• santiagoc93 (5/27/2016)


    select customerId, window, product, sales,

    ( Case when count(sales) over(partition by customerid order by customerid) >0 then 1 else 0 end)as class

    from #example

    Very nice!

    😎

    The addition of the ORDER BY eliminates the table spool operators and the query turns into a single index scan with stream aggregate if there is a POC index on the table .