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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:36:43+00:00 2026-05-18T22:36:43+00:00

I have a following example – table with name, department and country. I need

  • 0

I have a following example – table with name, department and country. I need to create a select statement that lists all records and assigns unique number to each group of department and country (column Group in the example):

Name   Department   Country   Group
====== ============ ========= =====
James  HR           UK        1
John   HR           UK        1
Alice  Finance      UK        2
Bob    Finance      DE        3
Frank  Finance      DE        3

I thought of some select with analytic function but I found only row_number() over (partition by department, country) which numbers records inside the group and not groups themselves. Do you have any idea how to solve this problem? Thank you!

  • 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-18T22:36:43+00:00Added an answer on May 18, 2026 at 10:36 pm
    SELECT  t.*, q.grp
    FROM    (
            SELECT  q.*, rownum AS grp
            FROM    (
                    SELECT  DISTINCT department, country
                    FROM    mytable
                    ORDER BY
                            department, country
                    ) q
            ) q
    JOIN    mytable t
    ON      t.department = q.department
            AND t.country = q.country 
    

    or

    SELECT  t.*, DENSE_RANK() OVER (ORDER BY department desc, country desc) AS grp
    FROM    mytable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following example code: create table Details( name varchar(20), age int, weight
I have following example: LIVE EXAMPLE My statement is returning false, why? if( $('.superstars-table
I have the following example code: create table #tempmembers ( memberid int ) update
I have the following example XML: <Table> <Row Position=0 Name=FName /> <Row Position=1 Name=LName
I have the following example code: $dataProvider = new CActiveDataProvider('firstTable', array('criteria' => array( 'select'
I have the following example in a SQL table Cust Group Sales A 1
I have the following example query: source = (SELECT DISTINCT source.* FROM (SELECT *
I have the following example which expresses the type of problem that I'm trying
I have the following example in Python to print a table: job_IDs = ['13453',
I have the following example code and let's say that MyCallable(B) takes longer than

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.