How can I create table which includes result of two table [message #373541] |
Mon, 23 April 2001 01:50 |
Karri Lahtela
Messages: 16 Registered: November 2000
|
Junior Member |
|
|
Hi
I have two table, one for positive value and other one for negative value.
Now I need to create result table, like belows.
SELECT PART_NO, OUTSALES FROM SALES
PART_NO OUT
------------------------- ---------
AC4505 -420.5887
AC4506 -248.484
AC4507 -14610.17
SELECT PART_NO, INSALES FROM INCOMES
PART_NO IN
------------------------- ---------
AC4505 400.6485
AC4506 202.322
AC4507 17461
How can I create table where is 'result' (IN+(-OUT))
like this:
PART_NO VALUE
AC4505 -19.9402
AC4506 -36.162
AC4507 2850.83
BR Karri
|
|
|
Re: How can I create table which includes result of two table [message #373544 is a reply to message #373541] |
Mon, 23 April 2001 04:57 |
Hans
Messages: 42 Registered: September 2000
|
Member |
|
|
Try this
drop table sales;
create table sales (
part_no varchar2(10),
col_out number(14,4)
);
insert into sales values ( 'AC4505', -420.5887 );
insert into sales values ( 'AC4506', -248.484 );
insert into sales values ( 'AC4507', -14610.17 );
commit;
drop table income;
create table income (
part_no varchar2(10),
col_in number(14,4)
);
insert into income values ( 'AC4505', 400.6485 );
insert into income values ( 'AC4506', 202.322 );
insert into income values ( 'AC4507', 17461 );
commit;
create table result as
select part_no, sum(result) result from
(
select part_no, col_out result from sales
union all
select part_no, col_in result from income
)
group by part_no;
|
|
|
|
|
|