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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:20:05+00:00 2026-06-17T05:20:05+00:00

Extending question which is there on Write sql query to wrap row data DEPARTMENT

  • 0

Extending question which is there on Write sql query to wrap row data

    DEPARTMENT  |   SUB_DEPT    |   EMPLOYEE    |   SALARY
    DEPT1       |   SUB_DEPT1   |   ABC         |   20000
    DEPT1       |   SUB_DEPT1   |   DEF         |   30000
    DEPT1       |   SUB_DEPT2   |   GHI         |   25000
    DEPT1       |   SUB_DEPT2   |   JKL         |   42000
    DEPT2       |   SUB_DEPT3   |   MNO         |   42500
    DEPT2       |   SUB_DEPT3   |   PQR         |   35000
    DEPT3       |   SUB_DEPT4   |   STU         |   36000
    DEPT3       |   SUB_DEPT5   |   VWX         |   36040

retrieve like

    DEPARTMENT  |   SUB_DEPT    |   EMPLOYEE    |   SALARY
    DEPT1       |   SUB_DEPT1   |   ABC         |   20000
                |               |   DEF         |   30000
                |   SUB_DEPT2   |   GHI         |   25000
                |               |   JKL         |   42000
    DEPT2       |   SUB_DEPT3   |   MNO         |   42500
                |               |   PQR         |   35000
    DEPT3       |   SUB_DEPT4   |   STU         |   36000
                |   SUB_DEPT5   |   VWX         |   36040

It means
1) Wrapping must apply for two columns.
2) Wrapping text must be for first row i.e. DEPT1 must present at first row only, DEPT2 present for 5th row.

Please help me out for this.

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-17T05:20:06+00:00Added an answer on June 17, 2026 at 5:20 am

    You can follow the same process as your original post. Create a row_number() for each unique department, then do the same thing for each unique department and sub_dept partition:

    select 
      case when deptrn = 1 then department else '' end department,
      case when SubDeptRn = 1 then sub_dept else '' end sub_dept,
      employee,
      salary
    from
    (
      select department, sub_dept, employee, salary,
        row_number() over(partition by department order by department, employee) DeptRn,
        row_number() over(partition by department, sub_dept order by department, sub_dept, employee) SubDeptRn
      from yourtable
    ) src
    

    See SQL Fiddle with Demo

    Result:

    | DEPARTMENT |  SUB_DEPT | EMPLOYEE | SALARY |
    ----------------------------------------------
    |      DEPT1 | SUB_DEPT1 |      ABC |  20000 |
    |            |           |      DEF |  30000 |
    |            | SUB_DEPT2 |      GHI |  25000 |
    |            |           |      JKL |  42000 |
    |      DEPT2 | SUB_DEPT3 |      MNO |  42500 |
    |            |           |      PQR |  35000 |
    |      DEPT3 | SUB_DEPT4 |      STU |  36000 |
    |            | SUB_DEPT5 |      VWX |  36040 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There has already been a question posted here which is very similar. Mine is
So I have a question of best practice in terms of extending functionality of
Just a general question regarding the difference between extending a class and implementing it.
I've a question. I have a dynamic menu contribution (class extending the ContributionItem ).
I have a ModalPopupExtender extending a panel and in the panel, there is a
I have a taskBarIcon element extending Application Context from which my entire UI is
I have an Engine which is extending another Engine's classes in its initializers like
I like the idea of extending on the client side classes that are data
Yes, there is a similar question here . However, that question doesn't seem to
What I am trying to do is to write a custom class extending Map[DateTime,

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.