34,592
社区成员
发帖
与我相关
我的任务
分享
select a.DocNum,a.CardName,Sum(b.OpenQty*b.Price) as '金额',
case when b.Currency!='RMB' then sum(b.GTotal/b.Quantity*b.OpenQty/b.rate) else sum(b.GTotal/b.Quantity*b.OpenQty) end as '净值',
Sum(b.OpenQty*b.Price)-sum(b.GTotal/b.Quantity*b.OpenQty) as '税收',a.NumatCard,a.DocDuedate,a.DocDate,a.TaxDate
from oqut as a left outer join QUT1 as b on a.DocEntry = b.DocEntry
group by a.DocNum,a.CardName,a.NumatCard,a.DocDuedate,a.DocDate,a.TaxDate
/*
代码报错,一直让我把b.Currency这个字段放入Group by里,但是我需要它来做判断,不知道有什么办法..
各位高手赐教啊...
*/
select a.DocNum,a.CardName,Sum(b.OpenQty*b.Price) as '金额',
sum(b.GTotal/b.Quantity*b.OpenQty/(case when b.Currency!='RMB' then b.rate else 1 end )) as '净值',
Sum(b.OpenQty*b.Price)-sum(b.GTotal/b.Quantity*b.OpenQty) as '税收',a.NumatCard,a.DocDuedate,a.DocDate,a.TaxDate
from oqut as a left outer join QUT1 as b on a.DocEntry = b.DocEntry
group by a.DocNum,a.CardName,a.NumatCard,a.DocDuedate,a.DocDate,a.TaxDate
select a.DocNum,a.CardName,Sum(b.OpenQty*b.Price) as '金额',
sum(case when b.Currency!='RMB' then b.GTotal/b.Quantity*b.OpenQty/b.rate else b.GTotal/b.Quantity*b.OpenQty end) as '净值',
Sum(b.OpenQty*b.Price)-sum(b.GTotal/b.Quantity*b.OpenQty) as '税收',
a.NumatCard,a.DocDuedate,a.DocDate,a.TaxDate
from oqut as a left outer join QUT1 as b on a.DocEntry = b.DocEntry
group by a.DocNum,a.CardName,a.NumatCard,a.DocDuedate,a.DocDate,a.TaxDate
--try
select a.DocNum,a.CardName,Sum(b.OpenQty*b.Price) as '金额'
,sum(case when b.Currency<>'RMB' then b.GTotal/b.Quantity*b.OpenQty/b.rate else b.GTotal/b.Quantity*b.OpenQty end) as '净值'
,Sum(b.OpenQty*b.Price)-sum(b.GTotal/b.Quantity*b.OpenQty) as '税收'
,a.NumatCard,a.DocDuedate,a.DocDate,a.TaxDate
from oqut as a left outer join QUT1 as b on a.DocEntry = b.DocEntry
group by a.DocNum,a.CardName,a.NumatCard,a.DocDuedate,a.DocDate,a.TaxDate