我试图得到两个日期q.atindt-q.orderdate
之间的差值,但是在某些情况下,我得到的数字像是被乘以两次或三次,有时看起来它在计算中没有模式,我尝试了max函数,但这没用....
concat(q.CHSeries,q.CHNumber) as "Chassi no.",q.CHNumber as "Chassi no.2",q.CHNumber *1 as "Chassi no.1",q.Model,q.ORDER,q.atindt as "Date of Invoice",q.atinvn as "Invoice no",q.customer as "Customer",q.orderdate as "Orderdate",(select coalesce(sum(lyamnt*lyICVL),0) from thf311 where q.order=lyorno)+
(select coalesce(sum(nmamnt*nmICVL),0) from thf351 where q.order=nmorno) as "Workshop Sales",(select coalesce(sum(lxamnt*lxICVL),0) from thf310 where q.order=lxorno) +
(select coalesce(sum(nlamnt*nlICVL),0) from thf350 where q.order=nlorno)as "Part Sales",0) from thf311 where q.order=lyorno) + (select coalesce(sum(lxamnt*lxICVL),0) from thf310 where q.order=lxorno)+
(select coalesce(sum(nmamnt*nmICVL),0) from thf351 where q.order=nmorno) + (select coalesce(sum(nlamnt*nlICVL),0) from thf350 where q.order=nlorno)
as "Total Sales",q.atindt-q.orderdate
FROM
(select ATVIN2,ATVIN3,ATPRDT,ATGNN2,aTorno,nlpcno,atindt,atinvn,atca30,atordt FROM THF020 h,THF350 WHERE nlBRNN=h.AtGNN2 AND nlORNO=h.AtORNO union select AtVIN2,AtVIN3,AtPRDT,AtGNN2,atorno,nmpcno,atordt
FROM THF020 h,THF351 WHERE nmBRNN=h.AtGNN2 AND nmORNO=h.AtORNO
union
select AjviN2,AjviN3,AJPRDT,AJGNN2,ajorno,lxpcno,ajindt,ajinvn,ajca30,ajordt FROM THF010 h,THF310 WHERE lxBRNN=h.AjGNN2 AND lxORNO=h.AjORNO union select AjviN2,AjviN3,AjPRDT,AjGNN2,lypcno,ajordt
FROM THF010 h,THF311 WHERE lyBRNN=h.AjGNN2 AND lyORNO=h.AjORNO) as q(CHSeries,CHNumber,Model,BRANCH,ORDER,PAYCDE,customer,orderdate)
where atindt>='2019-01-01' and atindt<='2019-10-25' and paycde>39 and paycde <60 and concat(q.CHSeries,q.CHNumber) in
(chassi 1,chassi2)
group by
concat(q.CHSeries,q.CHNumber),q.CHNumber,q.branch,q.atindt,q.atinvn,q.customer,q.orderdate```