试下这个
create table Product
(
ProductId nvarchar(8) primary key not null,--产品ID
ProductName nvarchar(16)--产品名
)
create table OrderItem
(
OrderItemId int identity(1,1) primary key not null ,--订单详细ID
OrderId nvarchar(13),--订单ID
ProductId nvarchar(8),--产品ID
Quantity int--订单项的产品数量
)
GO
---
insert into Product
select '01020111','Product1'
union all
select '01020112','Product2'
union all
select '01020113','Product3'
union all
select '01020114','Product4'
insert into OrderItem
select '001','01020111',3
union all
select '001','01020112',6
union all
select '001','01020113',2
union all
select '002','01020114',3
----select top 100 identity(int,1,1) as RowNum into #t from sysobjectsselect a.ProductID,c.ProductName from orderitem a ,#t b,Product c
where a.Quantity>=b.RowNum AND a.ProductID=c.ProductIDdrop table Product,OrderItem,#t
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货