谁能帮我解决以下问题。
create table [order1] (order_id int, CartTransaction_Id int, Status_Id int);
insert into [order1] values
(357488,87214,1),
(357489,87214,8),
(357490,87214,1),
(357491,87214,1),
(343980,87216,1),
(357483,87216,1);
create table [Status1] (Type VARCHAR(100), Status_Id int);
insert into [Status1] values
('New','1'),
('Awaiting Approval','8'),
('New','1'),
('New','1'),
('New','1'),
('New','1');
select
A.Order_Id, A.CartTransaction_Id, A.Status_Id, B.Type, B.Status_Id
FROM order1 A
JOIN dbo.Status1 B ON dbo.A.Status_Id = dbo.B.Status_Id
--AND B.Type = 'New'
order by A.CartTransaction_Id
下面是我从上面的查询中得到的输出。
以下是预期的结果
仅当 CartTransaction_Id 组中所有 order_id 的状态类型为“新”时,我才需要填充数据
从捐赠中,我需要过滤掉 CartTransaction_Id (87214),因为 order_id status_type 之一是在等待批准