C#中两个表的数据相减

来源:百度知道 编辑:UC知道 时间:2024/06/17 04:26:35
1. select wrrntID,wrrntName,count(wrrntID)as wrrntbooknum from wrrntAllStock where out_Flag is NULL group by wrrntID
2. select wrrntID,sum(wrrntBookNum)as nownum from T_GLD where IsInEveStock is NULL group by wrrntID
以上得到需要的字段,最后要得到wrrntID,wrrntName,wrrntbooknum,nownum,(wrrntbooknum-nownum),然后显示在另一个表中,怎么做啊?

select
wrrntID,wrrntName,wrrntbooknum,nownum,(wrrntbooknum-nownum)
FROM
(select wrrntID,wrrntName,count(wrrntID)as wrrntbooknum from wrrntAllStock where out_Flag is NULL group by wrrntID ) view_a LEFT JOIN
(select wrrntID,sum(wrrntBookNum)as nownum from T_GLD where IsInEveStock is NULL group by wrrntID )
view_b
on view_a.wrrntID=view_b.wrrntID

left join或者是cross join right join,根据你的数据表的逻辑关系定

楼上的差不多了
有null值的时候wrrntbooknum和nownum记得用case when 来判断