O'Reilly logo

Tera-Tom Genius Series - Hadoop Architecture and SQL by Jason Nolander, 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 9 – OLAP Functions

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

- Mohammed Ali

The Row_Number Command

SELECT Product_ID

,CAST(Sale_Time as Date) Sale_Time , Daily_Sales,

ROW_NUMBER() OVER

(ORDER BY Product_ID, Sale_Time) AS Seq_Number

FROM    Sales_Table  WHERE Product_ID IN (1000, 2000) ;

image

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

Quiz – How did the Row_Number Reset?

SELECT Product_ID

,CAST(Sale_Time as Date) Sale_Time , Daily_Sales,

ROW_NUMBER() OVER (PARTITION BY Product_ID

ORDER BY Product_ID, Sale_Time )   AS StartOver ...

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