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

  • Home
  • SEARCH
  • 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 9245781
In Process

The Archive Base Latest Questions

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

Here is a sample table that mimics my scenario: COL_1 COL_2 1 a 2

  • 0

Here is a sample table that mimics my scenario:

COL_1   COL_2       
1       a               
2       a               
9       b               
8       b               
11      b               

I have two columns where Column 1 have different numerical values and Column 2 represents different classes (a, b, c, etc.). In column 3 I would like to have them counted per class and matched with 0/1 numbers based on what was the biggest/lowest value in Column 1. So if in my example class “a” have only two values (in our example 1 and 2) they should be counted from 0 to 1 (where 0 stands for lowest number and 1 for biggest from Column 1). If class b is being represented by 3 entries I would like to have them matched by 0/1/2 numbers based on what is the biggest/lowest number from Column 1 in “b” class.

After my query I woul like to have something like this:

COL_1   COL_2   COL_3   
1       a       0       
2       a       1       
9       b       1       
8       b       0       
11      b       2       

So, in other words I want a query that looks how many duplicates we have in column 2 and gives them values from lowest to biggest (where 0 is lowest) based on what they are represented in column 1.

Thanks to anyone who helps me with this.

*I am using MS SQL, if that would make any difference.

  • 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-18T09:20:31+00:00Added an answer on June 18, 2026 at 9:20 am
    select 
        col_1,
        col_2,
        row_number() over(
            partition by col_2 order by col_1
        ) - 1 as col3
    from yourtablename
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the sample data for test table I have [childId] [parentId] [present] 1
I have a table that has three columns: myColumn, myColumn2 and myColumn3. The three
I have here sample table with three fields. TableA FieldA FieldB FieldC ====================================== 123XYZ456
I have a table with records that look like this: CREATE TABLE sample (
 I have a sample table of about 200 rows. The row contains a column,
I created a sample table on SQLite that has an Id column that is
Here's my scenario: I have a simple stored procedure that removes a specific set
I have a table with 20 columns that all display the same thing. I'm
I have a table which has two columns (id and word). I have an
I have an HTML table that looks like this: ------------------------------------------------- |Column 1 |Column 2

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.