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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:20:28+00:00 2026-06-14T09:20:28+00:00

Please refer below script declare @table1 table ( col1 int ) insert into @table1

  • 0

Please refer below script

            declare @table1 table
            (
            col1 int
            )  

            insert into @table1 values(1)
            insert into @table1 values(3)
            insert into @table1 values(3)
            insert into @table1 values(6)
            insert into @table1 values(4)
            insert into @table1 values(4)
            insert into @table1 values(4) 

The below query gives

            select col1 ,COUNT(col1) cntCol1 from @table1 group by col1

this output

            ----------------
            col1   | cntCol1
            -------| -------
            | 1    | 1    | 
            | 3    | 2    | 
            | 4    | 3    | 
            | 6    | 1    | 
            ---------------

is it possible to get the below output

            ----------------
            col1   | cntCol1
            -------| -------
            | 1    | 1    | 
            | 3    | 1    | 
            | 3    | 2    |  
            | 4    | 1    |  
            | 4    | 2    |  
            | 4    | 3    | 
            | 6    | 1    | 
            ---------------

If so, could you please help me with the query.

Thanks,
Esen.

  • 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-14T09:20:29+00:00Added an answer on June 14, 2026 at 9:20 am

    SQL Fiddle

          SELECT col1, ROW_NUMBER() OVER (partition by col1 order by col1) cntCol1
            FROM @table1
        ORDER BY col1, cntCol1    
    

    Sample Data:

     declare @table1 table
                (
                col1 int
                )  
    
                insert into @table1 values(1)
                insert into @table1 values(3)
                insert into @table1 values(3)
                insert into @table1 values(6)
                insert into @table1 values(4)
                insert into @table1 values(4)
                insert into @table1 values(4) 
    

    Results:

    | COL1 | CNTCOL1 |
    ------------------
    |    1 |       1 |
    |    3 |       1 |
    |    3 |       2 |
    |    4 |       1 |
    |    4 |       2 |
    |    4 |       3 |
    |    6 |       1 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please refer the below script declare @table1 table ( col1 int ) declare @table2
please refer to the code below. $dArr = '<script>document.write(volunteerDist);</script>'; $dArr gets the value of
Please refer to the image below - I'm not using NavigationViewController. Is there a
Please refer to this fiddle . While scrolling down, the table cells appear in
Please refer to the code below, when I comment in either of the commented
Please refer to the below code Specialized function in non specialized Template class Is
Please refer to my code below. When optimization in IAR MSP430 compiler is set
I'm creating a bash script that will load CSV files using SQL*Loader. Please refer
I have an NSArray output. please refer below. I want to sort based on
Please refer to the below jsfiddle code snippet: http://jsfiddle.net/JLXs5/3/ When the user clicks here,

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.