SQLServer查询: a.id与b.id相同时,a.id对应的a.p在b.id对应的b.p里找不到的话,就显示出这个a.id和a.p

img


想要如图查询,应该怎么写语句啊:
前提: a.id有的值,b.id基本都有 , 但a.id的值不会重复.
目的: a.id = b.id的情况下 , a.id对应的a.p在b.id对应的b.p里找不到的话 , 就显示出这个a.id和a.p

select * from aa_inventorypricetrace
where idinventory not in(
select aa_inventorypricetrace.idinventory 
from aa_inventorypricetrace,pu_purchasearrival_b
where aa_inventorypricetrace.idinventory=pu_purchasearrival_b.idinventory and aa_inventorypricetrace.latestsaleprice=pu_purchasearrival_b.origDiscountPrice
)


img


select a.id,a.p from a left join b on a.id=b.id where b.p!=a.p
select a.idinventory id ,
          case when nvl(b.origDiscountPrice,0)=0 then a.LatestPPrice else nvl(b.origDiscountPrice,0) end p
from AA_InventoryPriceTrace a
left join PU_PurchaseArriva1_b on a.idinventory =b.idinventory 

select a.id,a.p from a left join b on a.id=b.id where b.p!=a.p