Home » RDBMS Server » Server Administration » How can I create table which includes result of two table
How can I create table which includes result of two table [message #373541] Mon, 23 April 2001 01:50 Go to next message
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 Go to previous messageGo to next message
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;
Re: How can I create table which includes result of two table [message #373556 is a reply to message #373541] Mon, 23 April 2001 11:13 Go to previous messageGo to next message
Krishnan
Messages: 18
Registered: October 2000
Junior Member
You need to keep in mind create table as select .... will take all the constraints that are existing in the repective tables

-- KRishnan
Re: How can I create table which includes result of two table [message #373557 is a reply to message #373541] Mon, 23 April 2001 11:15 Go to previous messageGo to next message
Krishnan
Messages: 18
Registered: October 2000
Junior Member
oops it should read as 'will not take' instead of 'will take'
Re: How can I create table which includes result of two table [message #374277 is a reply to message #373557] Mon, 04 June 2001 05:44 Go to previous message
pardeep
Messages: 20
Registered: June 2001
Location: Chennai
Junior Member
create table new as select emp.empno,dept,deptno from emp,dept where emp.deptno=dept.deptno
Previous Topic: Re: difference between oracle 7 and oracle 8
Next Topic: CHECK CONSTRAINT - HARD FOR ME, EASY FOR YOU
Goto Forum:
  


Current Time: Thu Jul 04 02:41:42 CDT 2024