Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
T-SQL (SS2K5)
»
Wanting to learn. Who can best explain this...
Wanting to learn. Who can best explain this in a simple yet crystal manner to a noob??
Rate Topic
Display Mode
Topic Options
Author
Message
10e5x
10e5x
Posted Wednesday, January 09, 2013 2:39 AM
SSC Journeyman
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
Hi all,
I am very new to T-SQL.. and i came across this:
ROW_NUMBER ( )
OVER ( [ PARTITION BY value_expression , ... [ n ] ] order_by_clause )
Can someone explain to me how this works, its purpose and when do we usually use it for?
Am i asking for knowledge and i am very confident some1 from this excellent forum explain this well.
Post #1404619
anthony.green
anthony.green
Posted Wednesday, January 09, 2013 2:42 AM
SSCertifiable
Group: General Forum Members
Last Login: Friday, April 12, 2013 3:51 AM
Points: 5,075,
Visits: 4,831
Its a ranking function, which gives a list of rownumbers based on what you detail in the partitioning and ordering clauses.
The URL should explain it for you
http://msdn.microsoft.com/en-us/library/ms186734.aspx
Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1
&
Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger
Post #1404620
10e5x
10e5x
Posted Wednesday, January 09, 2013 2:58 AM
SSC Journeyman
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
Thanks, yup i read that must still not as clear....
Post #1404627
anthony.green
anthony.green
Posted Wednesday, January 09, 2013 2:59 AM
SSCertifiable
Group: General Forum Members
Last Login: Friday, April 12, 2013 3:51 AM
Points: 5,075,
Visits: 4,831
Can you explain which bits you are not clear on?
Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1
&
Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger
Post #1404628
10e5x
10e5x
Posted Wednesday, January 09, 2013 3:04 AM
SSC Journeyman
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
what does the partition does? and how does it affects the generating of row numbers. Does it have a similar function as GROUP BY?
Post #1404633
anthony.green
anthony.green
Posted Wednesday, January 09, 2013 3:08 AM
SSCertifiable
Group: General Forum Members
Last Login: Friday, April 12, 2013 3:51 AM
Points: 5,075,
Visits: 4,831
The partition will restart the row number based on that you detail.
So in the examples on the MSDN article, Example C uses partition, so that you can see the top person per region.
So if you look at the output, you will see its not a sequential series of numbers in the row_number column, it goes 1,2,3,1,1,1,1,2,1,2,3,4 etc and you can see that it restarts the row number for reach region.
So then the person can just say get me everyone where row number = 1 to get the top sales person for each region.
There is no group by for ROW_NUMBER as it is a ranking function and will always generate a unique row so you wont be able to group the data, that should be done before using row number.
Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1
&
Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger
Post #1404640
10e5x
10e5x
Posted Wednesday, January 09, 2013 3:27 AM
SSC Journeyman
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
Oh ok thanks... i uds le;)
Post #1404646
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.