sql

SELECT x.BillCode,x.BillDate,m.Code,m.Name,y.GoodsIdCode,y.GoodsIdName,y.PackageIdName,y.Price,y.LineDisc ,
y.NotUsedQ,(y.NotUsedQ - y.BackQ),y.Price*(y.NotUsedQ -
y.BackQ)*y.LineDisc as Money,y.UsedQ,y.Quantity,x.billcode,y.ToDate,y.nurseid,y.nurseid2,nurseid3
FROM tPosRetailNM x
LEFT JOIN tPosRetailND y ON x.KeyId=y.MasterId
LEFT JOIN tMember m ON x.MenberId=m.KeyId
LEFT JOIN tShop s ON x.ShopId = s.KeyId
Where (y.NotUsedQ - y.BackQ > 0) and (y.NotUsedQ > 0)
and EXISTS (SELECT rd.keyid FROM
tPosRetailD rd  left join tPosRetailm rm on rd.Masterid = rm.keyid  WHERE(rd.KeyId = y.FromDetailId)
AND  ((rd.Money <= rd.NurseId3 + rd.CommM + 0.1) or (rm.money =
rm.payed)))  --and ( s.code>='CD0008' )  and (s.code<='CD0008' )
--and  y.NotUsedQ<>y.Quantity
order by x.billdate

SELECT sum(y.Quantity) Quantity,sum(NotUsedQ) NotUsedQ,sum(y.Price) Price
--y.Price,
--(y.NotUsedQ - y.BackQ),y.UsedQ,y.Quantity
FROM tPosRetailNM x LEFT JOIN tPosRetailND y ON x.KeyId=y.MasterId LEFT
JOIN tMember m ON x.MenberId=m.KeyId LEFT JOIN tShop s ON x.ShopId = s.KeyId
Where (y.NotUsedQ - y.BackQ > 0) and (y.NotUsedQ > 0) and EXISTS (SELECT rd.keyid FROM
tPosRetailD rd  left join tPosRetailm rm on rd.Masterid = rm.keyid  WHERE(rd.KeyId = y.FromDetailId)
AND  ((rd.Money <= rd.NurseId3 + rd.CommM + 0.1) or (rm.money =
rm.payed)))  ---and ( s.code>='CD0002' )  and (s.code<='CD0002' ) 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值