2条回答 默认 最新
- Check_Const 2022-11-22 16:00关注
可以尝试用全连接 FULL join (FULL OUTER JOIN)
-- SQL Server 测试 (Oracle语法大部分类似) select case when A.物品名称 is not null then A.物品名称 else B.物品名称 end 物品名称, case when A.goods_id is not null then A.goods_id else B.material_id end 物品ID, case when A.supplier_id is not null then A.supplier_id else B.provider_id end 供应商ID, A.订单价格,B.进货价格 from ( select '足球' as 物品名称,'A001' as goods_id,'G001' as supplier_id,100 as 订单价格 union all select '排球' as 物品名称,'A004' as goods_id,'G004' as supplier_id,120 as 订单价格 ) as A Full join ( select '足球' as 物品名称,'A001' as material_id,'G001' as provider_id,50 as 进货价格 union all select '羽毛球' as 物品名称,'A002' as material_id,'G002' as provider_id,10 as 进货价格 union all select '乒乓球' as 物品名称,'A003' as material_id,'G003' as provider_id,5 as 进货价格 ) B on A.goods_id=B.material_id and A.supplier_id=B.provider_id
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报