mysql - SQL count function without limiting list due to WHERE -
i pretty new sql , trying generate report pulls kinds of different tables. simple select lines match parts keys no problem. although running issues when trying count how many times itemid shows in other tables.
one of tables has partid , kinds of information part. table has partid , itemid (there more 1 item each part). third tables has row of itemid shows each new repaired item in list.
i want able partid how many times associated itemids show in third table. have code follows:
select tblensembleunepiece.enspieceid, count(tblquarantaine.itemid) 'quarantine' tblensembleunepiece, tblitem, tblquarantaine tblensembleunepiece.nopiece<>'' , tblensembleunepiece.enspieceid = tblitem.enspieceid , tblquarantaine.itemid = tblitem.itemid group tblensembleunepiece.enspieceid;
this alone gives me list of partids , how many times associated itemids show third table. if again column code same principle:
select tblensembleunepiece.enspieceid, count(tblbonsortieitem.itemid) tblensembleunepiece, tblitem, tblbonsortieitem tblensembleunepiece.enspieceid = tblitem.enspieceid , tblbonsortieitem.itemid = tblitem.itemid , tblbonsortieitem.varevenir = 'true' group tblensembleunepiece.enspieceid;
this works on own , counts lines appear in third table itemids associated partid.
the problem comes when try combining all:
select tblensembleunepiece.enspieceid, tblensembleunepiece.nopiece 'part number', tblensembleunepiece.descriptionensp 'description', tblensembleunepiece.qtemin 'min', tblensembleunepiece.qtemax 'max', tbltypepiece.titretype, case when consommable='true' 'consumeable' else 'rotable' end 'utilization', sum(tblitem.nbpourpack) 'serviceable', count(case when tblquarantaine.ber = 'false' tblquarantaine.itemid else null end) 'quarantine repairable', count(case when tblquarantaine.ber = 'true' tblquarantaine.itemid else null end) 'quarantine ber/scrap', count(case when tblbonsortieitem.varevenir = 'true' tblbonsortieitem.itemid else null end) 'repair line' tblensembleunepiece, tbltypepiece, tblitem, tblquarantaine, tblbonsortieitem tblensembleunepiece.nopiece<>'' , tblensembleunepiece.typepieceid = tbltypepiece.typepieceid , tblensembleunepiece.enspieceid = tblitem.enspieceid , tblquarantaine.itemid = tblitem.itemid , tblbonsortieitem.itemid = tblitem.itemid group tblensembleunepiece.enspieceid;
what happens due statement limits amount of partids see because imposing many conditions , list not include parts need view.
how can partids want , fill in values need other 2 columns without imposing conditions? if dont show in third tables value zero.
Comments
Post a Comment