Home » SQL & PL/SQL » SQL & PL/SQL » Split rows into columns (4.0.2.15.21)
Split rows into columns [message #638732] Fri, 19 June 2015 05:57 Go to next message
SteveShephard
Messages: 41
Registered: August 2012
Member
Hi all,

Is there an easy way to split rows into columns?

I have the following bit of code which returns two totals


Select sum(amount)amount from table_a 
union
select sum(amount) amount from table_b 



which looks like this

800
900

but I would like it as follows

column a column b
800 900

Is this possible?

Many thanks Smile
Re: Split rows into columns [message #638733 is a reply to message #638732] Fri, 19 June 2015 06:06 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
Looks like a job for PIVOT
Re: Split rows into columns [message #638734 is a reply to message #638733] Fri, 19 June 2015 06:15 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Such as this simple query:
SQL> select (select sum(deptno) from dept) a,
  2         (select sum(empno)  from emp ) b
  3  from dual;

         A          B
---------- ----------
       100     108172

SQL>
Re: Split rows into columns [message #638736 is a reply to message #638732] Fri, 19 June 2015 06:52 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

For your information, you have to give your DATABASE version not your client tool one which by the way you didn't specify.

Previous Topic: Cross tab SQL query
Next Topic: 'Free text' select statment
Goto Forum:
  


Current Time: Thu Apr 25 22:00:27 CDT 2024