Rows to column

Posted on 2011-10-03
Last Modified: 2013-12-18

Below is the query which currently returns data as shown below:

Current Format:                  
WFC	                        559403	0	  204
WFC	                        559403	1012	  0
XXX	                        1000	1	  0
XXX	                        1000	0	  4

Open in new window

How should I modify this query to get the data in the format as shown below?
WFC	                        559403	1012	     204
XXX	                        1000	1	     4

Open in new window

SELECT  c.company_code,
            TO_CHAR(NVL(v_Count_700,0))                         v_Count_700,
            TO_CHAR(NVL(v_Count_704,0) +  NVL(v_Count_705,0))   v_Cosolidated_Count_1
    FROM    (SELECT  b.company_code,
                     CASE WHEN type = '700' THEN COUNT(*) END v_Count_700,
                     CASE WHEN type = '704' THEN COUNT(*) END v_Count_704,
                     CASE WHEN type = '705' THEN COUNT(*) END v_Count_705                      
               FROM  (SELECT a.company_code,
                        FROM a_log a ,
                             type_mvw t
                       WHERE a.type = t.type
                         AND t.type IN ('700','704','705')
                      ) b
             GROUP BY b.company_code,


Question by:sath350163
    LVL 76

    Accepted Solution

    Add a max.  Pasted on mobile.  Might have typos.

    SELECT  c.company_code,
                max(TO_CHAR(NVL(v_Count_700,0)))                         v_Count_700,
                max(TO_CHAR(NVL(v_Count_704,0) +  NVL(v_Count_705,0)))   v_Cosolidated_Count_1

    Group by company_code, user_id

    Author Comment

    Thanks slightwv.
    Your solution worked perfectly.

    Author Closing Comment

    Solution to convert individual rows to individual columns on the same row

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Suggested Solutions

    Title # Comments Views Activity
    Oracle Licensing on vCPU - Vmware 7 75
    SAP and ODBC links 2 65
    Create index on View 27 45
    Bulk insert into global temporary table 2 24
    Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
    Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
    This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
    This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now