首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

依主表中的数据查询出其字表中对应的明细解决方案

2012-01-15 
依主表中的数据查询出其字表中对应的明细设有以下主表:receiptdetIdnbrinventoryqtyponbrc0705a001100p001

依主表中的数据查询出其字表中对应的明细
设有以下主表:
receiptdet
Idnbr     inventory     qty       ponbr
c0705     a001               100       p001  
c0705     a001               50         p001

podet
ponbr       inventory         qty         recevdqty
p001         a001                   200         150  


有以上的两个表,其中receiptdet表中的ponbr来源于表中podet表中的ponbr,
receiptdet表中的inventory需要存在于podet表中的inventory字段值.
receiptdet表中的QTY字段必须小于或等于podet表中的QTY字段.
receiptdet表中的QTY字段必须等于podet表中的recevdqty字段.


现在我想写这样的一个查询语句:
在PODET中查询出符合   podet.recevdqty     <>   sum(receiptdet.qty)   这样的数据来,
请问一下SQL语句如何写呢?

谢谢了!!!




[解决办法]
select ponbr,inventory,sum(qty) from receiptdet a group by ponbr,inventory
having sum(Qtyp) <> (select recevdqty from podet b where a.ponbr=b.ponbr and a.inventory=b.inventory)
[解决办法]
select * from (select inventory , sum(qty) as qty from receiptdet group by inventory ) a, podet b
where a.inventory=b.inventory and a.qty <=b.qty and a.qty=b.recevdqty

热点排行