日期:2014-05-17 浏览次数:20659 次
if object_id('[TBA]') is not null drop table [TBA]
go
create table [TBA] (编码 int,名称 nvarchar(4))
insert into [TBA]
select 1,'苹果' union all
select 2,'梨'
select * from [TBA]
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (编码 int,数量 int,价格 numeric(2,1))
insert into [TB]
select 1,20,5 union all
select 2,10,6 union all
select 1,10,5.1 union all
select 1,5,5.2 union all
select 2,30,5.8
select * from [TB]
SELECT A.编码,
(SELECT 名称 FROM TBA WHERE TBA.编码=A.编码) AS 名称,
A.数量 ,
上次价格 = ( SELECT 价格