O'Reilly logo

Microsoft Azure SQL Data Warehouse - Architecture and SQL by Todd Wilson, Tom Coffing

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14 – Window Functions OLAP

“Don’t count the days, make the days count.”

- Mohammad Ali

The Row_Number Command

SELECT Product_ID ,Sale_Date , Daily_Sales,

ROW_NUMBER() OVER

(ORDER BY Product_ID, Sale_Date) AS Seq_Number

FROM   Sales_Table WHERE Product_ID IN (1000, 2000) ;

image

The ROW_NUMBER() Keyword(s) caused Seq_Number to increase sequentially. Notice that this does NOT have a Rows Unbounded Preceding, and it still works!

Quiz – How did the Row_Number Reset?

SELECT Product_ID ,Sale_Date , Daily_Sales,

               ROW_NUMBER() OVER (PARTITION BY Product_ID

     ORDER BY Product_ID, Sale_Date  )   AS StartOver

FROM   Sales_Table WHERE ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required