Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7507823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:33:47+00:00 2026-05-29T22:33:47+00:00

I am trying to get the over and partition by functionality wrapped around my

  • 0

I am trying to get the over and partition by functionality wrapped around my head. Here is an example that I just do not understand.

Here is the data I have:

SALESORDERID       ORDERDATE 
43894              08/01/2001 
43664              07/01/2001 
43911              08/01/2001 
43867              08/01/2001 
43877              08/01/2001 
44285              10/01/2001 
44501              11/01/2001 
43866              08/01/2001 
43895              08/01/2001 
43860              08/01/2001

When I run this query:

select Row_Number() over(partition by orderdate order by orderdate asc) 
    as Rownumber, salesorderid, orderdate
from test2
order by rownumber

Here are the results I get:

ROWNUMBER     SALESORDERID       ORDERDATE 
1             43664              07/01/2001 
1             43911              08/01/2001 
1             44109              09/01/2001 
1             44483              11/01/2001 
1             44285              10/01/2001 
2             43867              08/01/2001 
2             44501              11/01/2001 
3             43895              08/01/2001 
4             43894              08/01/2001 
5             43877              08/01/2001 

Can someone explain this query to me. I am not new to SQL but windowing I have been struggling with and can’t get my head wrapped around this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:33:48+00:00Added an answer on May 29, 2026 at 10:33 pm

    Try ordering by order date, you’ll see the results more easily

    select Row_Number() over(partition by orderdate order by orderdate asc) 
        as Rownumber, salesorderid, orderdate
    from test2
    order by orderdate;
    

    should give (i’ve added blank lines for clarity)

    ROWNUMBER     SALESORDERID       ORDERDATE
    1             43664              07/01/2001
    
    1             43911              08/01/2001
    2             43867              08/01/2001
    3             43895              08/01/2001
    4             43894              08/01/2001
    5             43877              08/01/2001
    
    1             44109              09/01/2001
    
    1             44285              10/01/2001
    
    1             44483              11/01/2001
    2             44501              11/01/2001
    

    You’ll notice that the result is divided into ‘partitions’, each partition being the set of rows with identical orderdates. That is what ‘partition by orderdate’ means.

    Within a partition, the rows are ordered by orderdate, as per the second clause of ‘(partition by orderdate order by orderdate asc)’. That isn’t very useful, as all rows within a partition are going to have the same orderdate. Because of that, the ordering of the rows within a partition is random. Try ordering by salesorderid within the partition by clause to have a more reproducable result.

    row_number() just returns the row’s ordering within each partition

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just trying to get more into stl semantics, and converting old loops over
I've spent over half a day on this - just trying to get the
I'm having a hardcore head-ache from trying to get complete programmatic control over rendering
I am trying to get 2 programs to share encrypted data over a network
I'm trying to get emacs tramp running under Windows XP to work over putty
I'm trying to get a queryset to issue its query over a different DB
I'm trying to get secure web service connectivity on the iPhone over https via
I have css hover over images for my tabs and I'm trying to get
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I'm trying to get the nav-bar to position over the image using CSS. Yet,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.