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 8819999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:30:06+00:00 2026-06-14T05:30:06+00:00

This one is hard to explain. I’m trying to do a Row_Number() Over(Order by

  • 0

This one is hard to explain. I’m trying to do a Row_Number() Over(Order by PickedDate) in my select insert into a new table.

This works fine for producing 1,2,3,4,5,6,7, but that’s not what i’m looking to do. I’m Looking to generate the row back at the number one for each grouping of fruit.

For example I have the following table structure i’m trying to insert into; ItemOrder int, FruitType nvarchar(100),DatePicked datetime,

with the following data

FruitType|DatePicked  
Apple|10/1/2012  
Apple|10/3/2012  
Apple|10/2/2012  
Plum|9/13/2011  
Plum|9/14/2011  
Plum|9/15/2011
Cherry|12/2/2012
Cherry|12/4/2012

I’m trying to get the following result

FruitType|DatePicked|ItemOrder
Apple|10/1/2012|1
Apple|10/3/2012|3
Apple|10/2/2012|2
Plum|9/13/2011|1  
Plum|9/14/2011|2  
Plum|9/15/2011|3
Cherry|12/2/2012|1
Cherry|12/4/2012|2

to help everybody out

CREATE TABLE #FruitStandPicked
(
   FruitType    NVARCHAR (100),
   DatePicked   DATETIME
);



INSERT INTO #FruitStandPicked (FruitType, DatePicked)
VALUES ('Apple', '10/1/2012'),
       ('Apple', '10/3/2012'),
       ('Apple', '10/2/2012'),
       ('Plum', '9/13/2011'),
       ('Plum', '9/14/2011'),
       ('Plum', '9/15/2011'),
       ('Cherry', '12/2/2012'),
       ('Cherry', '12/4/2012');


CREATE TABLE #FruitStandTable
(
   Itemorder    INT,
   FruitType    NVARCHAR (100),
   DatePicked   DATETIME
);

--this needs the tweak
INSERT INTO #FruitStandTable (ItemOrder, FruitType, DatePicked)
   SELECT row_number () OVER (ORDER BY fruittype, datepicked),
          FruitType,
          DatePicked
     FROM #FruitStandPicked;

SELECT * FROM #FruitStandTable;

DROP TABLE #FruitStandTable;
     DROP TABLE #FruitStandPicked;

Again that works to the extent of making the order, but I need the order by grouping also.

Thanks in advance!

  • 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-06-14T05:30:08+00:00Added an answer on June 14, 2026 at 5:30 am

    You can still use ROW_NUMBER with PARTITION clause.
    Try this:

    SELECT *, ROW_NUMBER() OVER(PARTITION BY Fruit ORDER BY PickedDate) ItemOrder
      FROM <YOUR-TABLE>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one is kind of hard to explain. But basically, I'm trying to nest
I am having a hard time on this one, I have a folder over
I am having one heck of a hard time trying to figure this out.
Bear with me, this one is hard to explain. I hope some hero out
this one is hard to explain! I am writing a python application to be
its hard for me to explain this one, but i hope some code will
This is a hard one to explain but here goes. I have 2 arrays,
Hard to explain this one, but here it goes: I'm using jQuery to add
This is one of those hard to explain questions. I've tried my best below,
An unusual one this, and a toughie to explain eloquently! I'm trying to force

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.