You Asked
Hai, Tom sir...I have table with columns like this...I have 6 columns in my table with data in below.I need to write
an SQL code to get the in below output.Out i mentioned at the ending.Please look at and give me the sol.
Create table t3
(
col1 date,
col2 varchar2(10),
col3 number,
col4 varchar2(10),
col5 number,
col6 varchar2(10)
)
;
Insert into t3 values(to_date('02-05-2018','dd-mm-yyyy'),'IZ231',9,'jan',27,'jan');
Insert into t3 values(to_date('02-05-2018','dd-mm-yyyy'),'IZ232',8,'Mar',99,'Mar');
select * from t3
;
COL1 COL2 COL3 COL4 COL5 COL6
02-MAY-18 IZ231 9 jan 27 jan
02-MAY-18 IZ232 8 Mar 99 Mar
Here in below is my output
Output
*******
02-05-2018 IZ231 9 jan
02-05-2018 IZ231 27 Jan
02-05-2018 IZ232 8 Mar
02-05-2018 IZ232 99 Mar
Note:-Write an SQL code here to get my above Output.
Thanks In advance.
and Connor said...
SQL> Create table t3
2 (
3 col1 date,
4 col2 varchar2(10),
5 col3 number,
6 col4 varchar2(10),
7 col5 number,
8 col6 varchar2(10)
9 )
10 ;
Table created.
SQL>
SQL> Insert into t3 values(to_date('02-05-2018','dd-mm-yyyy'),'IZ231',9,'jan',27,'jan');
1 row created.
SQL> Insert into t3 values(to_date('02-05-2018','dd-mm-yyyy'),'IZ232',8,'Mar',99,'Mar');
1 row created.
SQL> select * from t3;
COL1 COL2 COL3 COL4 COL5 COL6
--------- ---------- ---------- ---------- ---------- ----------
02-MAY-18 IZ231 9 jan 27 jan
02-MAY-18 IZ232 8 Mar 99 Mar
SQL>
SQL>
SQL>
SQL> select col1, col2, col3, col4
2 from t3
3 union all
4 select col1, col2, col5, col6
5 from t3
6 order by 1,2,3;
COL1 COL2 COL3 COL4
--------- ---------- ---------- ----------
02-MAY-18 IZ231 9 jan
02-MAY-18 IZ231 27 jan
02-MAY-18 IZ232 8 Mar
02-MAY-18 IZ232 99 Mar
Rating
(3 ratings)
Is this answer out of date? If it is, please let us know via a Comment