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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:33:28+00:00 2026-05-26T08:33:28+00:00

example select: select * from ( select 1 cnt, 2 sm, ’55’ name, 12

  • 0

example select:

select *
from (
    select 1 cnt, 2 sm, '55' name, 12 month, 2011 year, '12 2011' mnth_txt from dual union all
    select 1 cnt, 2 sm, '54' name, 11 month, 2011 year, '11 2011' mnth_txt from dual union all
    select 1 cnt, 2 sm, '55' name, 11 month, 2011 year, '11 2011' mnth_txt from dual union all
    select 1 cnt, 2 sm, '54' name, 12 month, 2011 year, '12 2011' mnth_txt from dual union all
    select 1 cnt, 2 sm, '55' name, 12 month, 2011 year, '12 2011' mnth_txt from dual union all
    select 1 cnt, 2 sm, '56' name, 12 month, 2010 year, '12 2010' mnth_txt from dual  
) pivot (
    sum(cnt) cnt, sum(sm) sm
    for name in
            ( '55' as "Omsk"
            , '54' as "Novosibirsk"
            , '56' as "Orenburg"
            )
)

output:

|month| year | mnth_txt |Omsk_cnt|Omsk_sm|Novosibirsk_cnt|Novosibirsk_sm|Orenburg_cnt| Orenburg_sm|
| 12  | 2010 |'12 2010' | (null) | (null)| (null)        | (null)       | 1          | 2          |
| 12  | 2011 |'12 2011' | 2      | 4     | 1             | 2            | (null)     | (null)     |
| 11  | 2011 |'11 2011' | 1      | 2     | 1             | 2            | (null)     | (null)     |

is it possible to sort the records in chronological order, with the excluding columns “month” and “year”?
Without listing all the columns.

UPD

need:

| mnth_txt |Omsk_cnt|Omsk_sm|Novosibirsk_cnt|Novosibirsk_sm|Orenburg_cnt| Orenburg_sm|
|'12 2010' | (null) | (null)| (null)        | (null)       | 1          | 2          |
|'11 2011' | 1      | 2     | 1             | 2            | (null)     | (null)     |
|'12 2011' | 2      | 4     | 1             | 2            | (null)     | (null)     |

something like:

select mnth_txt, pivoted_columns.*
  • 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-26T08:33:29+00:00Added an answer on May 26, 2026 at 8:33 am

    To sort the records you can add the following to the end of your sql

    ORDER BY TO_DATE('01/'||month||'/'||year,'dd/mm/yyyy') 
    

    Note: The pivot column names are case sensitive so you need to quote them

    here’s the full query, selecting only the columns you require:

     SELECT mnth_txt,"Omsk_CNT","Omsk_SM","Novosibirsk_CNT",
            "Novosibirsk_SM","Orenburg_CNT","Orenburg_SM" 
     FROM
     (
     SELECT *
     FROM (     
      SELECT 1 cnt, 2 sm, '55' name, 12 month, 2011 year, '12 2011' mnth_txt FROM DUAL UNION ALL     
      SELECT 1 cnt, 2 sm, '54' name, 11 month, 2011 year, '11 2011' mnth_txt FROM DUAL UNION ALL    
      SELECT 1 cnt, 2 sm, '55' name, 11 month, 2011 year, '11 2011' mnth_txt FROM DUAL UNION ALL     
      SELECT 1 cnt, 2 sm, '54' name, 12 month, 2011 year, '12 2011' mnth_txt FROM DUAL UNION ALL     
      SELECT 1 cnt, 2 sm, '55' name, 12 month, 2011 year, '12 2011' mnth_txt FROM DUAL UNION ALL     
      SELECT 1 cnt, 2 sm, '56' name, 12 month, 2010 year, '12 2010' mnth_txt FROM DUAL   ) 
      PIVOT ( SUM(cnt) cnt, SUM(sm) sm     
              FOR NAME IN             
              ( '55' AS "Omsk",'54' AS "Novosibirsk", '56' AS "Orenburg" ) 
            )
      ORDER BY TO_DATE('01/'||month||'/'||year,'dd/mm/yyyy')         
     )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Union Query. Here's a basic (similar) example: SELECT a.Name, b.Info FROM
If I have a few UNION Statements as a contrived example: SELECT * FROM
For example, mysql quote table name using SELECT * FROM `table_name`; notice the `
example - select * from discussion where title like '%india%' UNION select * from
For example: SELECT * FROM atable ORDER BY num; 'atable' is: num name 1
For example: select * from T where T.id IN(4,78,12,45) I want the returned record
I need to execute a SQL Query between two databases. Example: SELECT * from
Example: select ename from emp where hiredate = todate('01/05/81','dd/mm/yy') and select ename from emp
For example which is better: select * from t1, t2 where t1.country='US' and t2.country=t1.country
For example, select * from x where crc=CRC32('Hi') does the CRC32 function get run

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.