Tuesday, July 8, 2014

Sql Query Stock And Sale

create table total(id int identity(1,1) primary key,item varchar(50),one int,two int)

insert into total values('Chair',5,8),('Table',9,9)
select * from total

create table done(id int identity(1,1) primary key,item varchar(50),one int,two int)
insert into done values('Chair',1,5),('Table',3,3)


select * from total
select * from done
select x.id,x.item,x.one-y.one as one,x.two-y.two as two
from total x
left outer join

done y on x.id=y.id