Hi there,The following is my table whereby i have joined projects table with issue table (this is 1 to many relationship).
I have the following query: SELECT odf.mbb_sector sectorid,SUM(case when odf.mbb_projecttype = 'lkp_val_appl' then 1 else 0 end) total_appl,SUM(case when odf.mbb_projecttype = 'lkp_val_infrastructure' then 1 else 0 end) total_infra,SUM(case when odf.mbb_projecttype = 'lkp_val_eval' then 1 else 0 end) total_eval,SUM(case when odf.mbb_projecttype = 'lkp_val_subproject' then 1 else 0 end) total_subprj,SUM(case when odf.mbb_projecttype = 'lkp_val_nonit' then 1 else 0 end) total_nonit,SUM(case when odf.mbb_projecttype = 'lkp_val_adhocrptdataextract' or odf.mbb_projecttype = 'lkp_val_productionproblem' or odf.mbb_projecttype = 'lkp_val_maintwoprogchange' then 1 else 0 end) total_others,COUNT(distinct prj.prid) total_prjFROM PRJ_PROJECTS AS PRJ,SRM_PROJECTS AS SRM,ODF_CA_PROJECT AS ODFLEFT JOIN RIM_RISKS_AND_ISSUES AS RRI ON RRI.pk_id = odf.idWHERE prj.prid = srm.idAND srm.id = odf.idAND srm.is_active =1 AND odf.mbb_projecttype not in ('lkp_val_budget','lkp_val_itpc')AND odf.mbb_funcunit = 'lkp_val_operation'GROUP BY odf.mbb_sector
which returns me the following result :
. The problem is at the lkp_val_infosystem where it returns 3 instead of 1 in the total_infra column. How do I correct my case stmt to return the correct no of projects breakdown by different project type? Currently, only the total_prj which returns correct data. Thanks