Solved

# Rows to column

Posted on 2011-10-03
420 Views
Last Modified: 2013-12-18
Hello,

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
``````
How should I modify this query to get the data in the format as shown below?
``````WFC	                        559403	1012	     204
XXX	                        1000	1	     4
``````

SELECT  c.company_code,
c.user_id,
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,
b.user_id,
b.type,
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,
a.user_id,
a.type
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,
b.user_id,
b.type
)c;

Thanks!

0
Question by:sath350163
3 Comments

LVL 76

Accepted Solution

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

SELECT  c.company_code,
c.user_id,
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
0

Author Comment

Thanks slightwv.
Your solution worked perfectly.
0

Author Closing Comment

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

## Write Comment

Please enter a first name

Please enter a last name

We will never share this with anyone.

## Featured Post

### 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.

#### Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!