Home » SQL & PL/SQL » SQL & PL/SQL » help needed in simple sql
help needed in simple sql [message #8379] Thu, 14 August 2003 04:27 Go to next message
krs
Messages: 9
Registered: November 2001
Junior Member
create table test1(col1 varchar2(10),col2 number(5))

insert into test1 values('T1',10)
insert into test1 values('T1',5)
insert into test1 values('T2',25)
insert into test1 values('T2',5)
insert into test1 values('T2',10)

select col1,count(col2) from test1 group by col1

COL1 col2
---------- -----------
T1 2
T2 3

Now i want the data to be displayed in the format

T1 T2
2 3

How can i get this,can anyone help me with the code

Thanks in advance
Re: help needed in simple sql [message #8381 is a reply to message #8379] Thu, 14 August 2003 06:26 Go to previous message
Jeanne
Messages: 26
Registered: June 2003
Junior Member
Here is the SQL for you:
select T1, T2 from
(select decode(col1, 'T1', count(col2)) T1
from test1
where col1 = 'T1'
group by col1) a,
(select decode(col1, 'T2', count(col2)) T2
from test1
where col1 = 'T2'
group by col1) b
Previous Topic: STORE SET filename .........output suppress
Next Topic: reading data from double datatype column in a user readable format
Goto Forum:
  


Current Time: Fri Apr 19 03:54:08 CDT 2024