sql - I have NULL results for thousands of rows. How do I exclude those from populating when they don't exist? -
i have code @ sales employee of mine. hired create growth on extinct customers. on 1,000+ customers have in dbase, effect 100. there have been lot of rows generated value null
. want report exclude rows of customers more efficient in understanding management. how accomplish this?
select t1.cardcode 'bp code', t1.cardname 'bp name', count(case when t1.slpcode<>'37' t0.docnum end) '# of orders', sum(case when t1.slpcode<>'37' t0.doctotal end) 'total orders amt', sum(case when t1.slpcode<>'37' t0.doctotal end)/ count(case when t1.slpcode<>'37' t0.docnum end) 'avg order size', count(case when t1.slpcode='37' t0.docnum end) '# of orders', sum(case when t1.slpcode='37' t0.doctotal end) 'total orders amt', sum(case when t1.slpcode='37' t0.doctotal end)/ count(case when t1.slpcode='37' t0.docnum end) 'avg order size' ordr t0 inner join ocrd t1 on t0.cardcode=t1.cardcode t0.docstatus = 'c' , t0.canceled <> 'y' , t0.docdate >= '2015-05-26' group t1.cardcode, t1.cardname order t1.cardname
select tnot.*, tyes.* ( select ocrd.cardcode 'bp code', ocrd.cardname 'bp name', count(ordr.docnum) '# of orders', sum(ordr.doctotal) 'total orders amt' ocrd left join ordr on ordr.cardcode= ocrd.cardcode , ordr.canceled <> 'y' , ordr.docdate >= '2015-05-26' , ocrd.slpcode <> '37' group ocrd.cardcode, ocrd.cardname ) tnot join ( select ocrd.cardcode 'bp code', ocrd.cardname 'bp name', count(ordr.docnum) '# of orders', sum(ordr.doctotal) 'total orders amt' ocrd join ordr on ordr.cardcode= ocrd.cardcode , ordr.canceled <> 'y' , ordr.docdate >= '2015-05-26' , ocrd.slpcode = '37' group ocrd.cardcode, ocrd.cardname ) tyes on tnot.[bp code] = tyes.[bp code] , tnot.[bp name] = tyes.[bp name] order tyes.[bp name]
Comments
Post a Comment