Hi,
I need a query which would convert Rows into Columns without causing any damages to the original data. I am not supposed to solve this by creating temporary tables and later dropping it.
I have a table which is in the below format:
LOGTYPE CLLI SWREL RPTDATE CNAME CVALUE
avl-stplan tahlt01 EAGLE537 08/11/2007 TCPRSTSENT 12
avl-stplan tahlt01 EAGLE537 08/11/2007 IPHDRERR 88
avl-stplan tahlt01 EAGLE537 08/11/2007 IPADDRERR 65
avl-stplan tahlt01 EAGLE537 08/11/2007 IPPROTERR 34
avl-stplan tahlt01 EAGLE537 08/11/2007 STATUS N
avl-stplan tahlt01 EAGLE537 08/11/2007 TYPE LIM
avl-stplan tahlt01 EAGLE537 08/11/2007 LOC 1216
avl-stplan tahlt02 EAGLE537 08/11/2007 TCPRSTSENT 40
avl-stplan tahlt02 EAGLE537 08/11/2007 IPHDRERR 22
avl-stplan tahlt02 EAGLE537 08/11/2007 IPADDRERR 60
avl-stplan tahlt02 EAGLE537 08/11/2007 IPPROTERR 28
avl-stplan tahlt02 EAGLE537 08/11/2007 STATUS K
avl-stplan tahlt02 EAGLE537 08/11/2007 TYPE LIM
avl-stplan tahlt02 EAGLE537 08/11/2007 LOC 1209
I need a Output which has the following format:
LOGTYPE CLLI SWREL RPTDATE TCPRSTSENT IPHDRERR IPADDRERR IPPROTERR STATUS TYPE LOC
avl-stplan tahlt01 EAGLE537 08/11/2007 12 88 65 34 N LIM 1216
avl-stplan tahlt02 EAGLE537 08/11/2007 40 22 60 28 K LIM 1209
NOTE: I just gave above data as a sample. Actually the number of CNAME rows is more than 30 per (LOGTYPE and CLLI and RPTDATE). For this reason, (if available) I do not want write every CNAME in solution sql.
Please help with some solution.
Thanks,
Recep
2 1927
Here's how you can do a pivot query in Oracle: - chris@XE> drop table t;
-
-
Table dropped.
-
-
Elapsed: 00:00:00.04
-
chris@XE>
-
chris@XE> create table t (
-
2 LOGTYPE varchar2(20),
-
3 CLLI varchar2(20),
-
4 SWREL varchar2(20),
-
5 RPTDATE date,
-
6 CNAME varchar2(20),
-
7 CVALUE varchar2(20)
-
8 );
-
-
Table created.
-
-
Elapsed: 00:00:00.01
-
chris@XE>
-
chris@XE> insert into t values('avl-stplan', 'tahlt01', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'TCPRSTSENT' ,'12');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> insert into t values('avl-stplan', 'tahlt01', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'IPHDRERR' ,'88');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> insert into t values('avl-stplan', 'tahlt01', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'IPADDRERR' ,'65');
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
chris@XE> insert into t values('avl-stplan', 'tahlt01', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'IPPROTERR' ,'34');
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
chris@XE> insert into t values('avl-stplan', 'tahlt01', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'STATUS' ,'N');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> insert into t values('avl-stplan', 'tahlt01', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'TYPE' ,'LIM');
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
chris@XE> insert into t values('avl-stplan', 'tahlt01', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'LOC' ,'1216');
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
chris@XE> insert into t values('avl-stplan', 'tahlt02', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'TCPRSTSENT' ,'40');
-
-
1 row created.
-
-
Elapsed: 00:00:00.00
-
chris@XE> insert into t values('avl-stplan', 'tahlt02', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'IPHDRERR' ,'22');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> insert into t values('avl-stplan', 'tahlt02', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'IPADDRERR' ,'60');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> insert into t values('avl-stplan', 'tahlt02', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'IPPROTERR' ,'28');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> insert into t values('avl-stplan', 'tahlt02', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'STATUS' ,'K');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> insert into t values('avl-stplan', 'tahlt02', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'TYPE' ,'LIM');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE> insert into t values('avl-stplan', 'tahlt02', 'EAGLE537', to_date('08/11/2007','dd/mm/yyyy'), 'LOC' ,'1209');
-
-
1 row created.
-
-
Elapsed: 00:00:00.01
-
chris@XE>
-
chris@XE> commit;
-
-
Commit complete.
-
-
Elapsed: 00:00:00.01
-
chris@XE>
-
chris@XE> select * from t
-
2
-
chris@XE> SELECT logtype,
-
2 clli,
-
3 swrel,
-
4 rptdate,
-
5 MAX (DECODE (cname,'TCPRSTSENT', cvalue)) tcprstsent,
-
6 MAX (DECODE (cname,'IPHDRERR', cvalue)) IPHDRERR,
-
7 MAX (DECODE (cname,'IPADDRERR', cvalue)) IPADDRERR,
-
8 MAX (DECODE (cname,'IPPROTERR', cvalue)) IPPROTERR,
-
9 MAX (DECODE (cname,'STATUS', cvalue)) STATUS,
-
10 MAX (DECODE (cname,'TYPE', cvalue)) TYPE,
-
11 MAX (DECODE (cname,'LOC', cvalue)) LOC
-
12 FROM t
-
13 GROUP BY logtype,
-
14 clli,
-
15 swrel,
-
16 rptdate;
-
-
LOGTYPE CLLI SWREL RPTDATE TCPRSTSENT IPHDRERR IPADDRERR IPPROTERR STATUS TYPE LOC
-
----------- -------- --------- ------------ ----------- --------- ---------- ---------- ------- ----- -----
-
avl-stplan tahlt02 EAGLE537 08-NOV-2007 40 22 60 28 K LIM 1209
-
avl-stplan tahlt01 EAGLE537 08-NOV-2007 12 88 65 34 N LIM 1216
-
-
Elapsed: 00:00:00.03
-
chris@XE>
-
Please find a related discussion here and few others in the How To section of Oracle.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Marek Mänd |
last post by:
Please explain to a experienced fool like me, how to hide table rows
correctly at this case.
http://marekmand.kuubik.ee/iebug_canthide_table_rows_properly.htm
Click on the header "label" and see...
|
by: Jim Heavey |
last post by:
Trying to figure out the technique which should be used
to add rows to a datagrid. I am thinking that I would
want an "Add" button on the footer, but I am not quite
sure how to do that. Is that...
|
by: Andrew |
last post by:
Hey all,
I am very new to ASP.Net (and .Net in general), but that isn't stopping the
boss from wanting to begin new projects in it. This latest project has me
kinda stumped and after a couple...
|
by: Ramakrishnan Nagarajan |
last post by:
Hi,
I am converting Excel data into a Dataset in C#. There are around 24 columns
in the Excel Sheet.
First I tried to insert one row with correct values in the Excel sheet. i.e.
for text columns...
|
by: ppateel |
last post by:
Hi,
I am new to c++ and I am converting a c program to c++. I changed
malloc call to new and I am getting an exception violation. Here is the
relevant piece of code.
Compiler vc++ 7.0 (.Net...
|
by: JoeM |
last post by:
I have a list of data in a database(access). How can I get the total rows
in the database?
Thanks
|
by: Susan Mackay |
last post by:
I have a data table that is connected to a database table with a data
adapter in the 'standard' manner.
However I want to be able to remove selected rows from the data table (i.e.
no longer...
|
by: Vasuki Masilamani |
last post by:
Hi,
I need a query which would convert Columns into Rows without causing any damages to the original data. I am not supposed to solve this by creating temporary tables and later dropping it.
I...
|
by: Orbie |
last post by:
Hi Guys,
I need some help with pivoting or converting some rows on a Table into columns using SQL Server 2008! I have a Table which contains the same Products in 4 different Stores. I'm only...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |