Hello.
Help. I cannot figaure out what is wrong with this SQL.
I am trying to display an average cycle time per site.
I end up getting the same result for all sites.
Thanks in advance.
-Cassie
select SITE, AVG(CycleTime) as AVG_CT
from
(select SITE, ROUND(DEC_DATE-VIS_DATE,2) as CycleTime
from
(select PROJ, SITE, BSLN, VIS_NUM,
VIS_DATE,max(EFF_DATE) as DEC_DATE
from
(select vm.proj_id as PROJ,
pi.waes_site_cd as SITE,
vm.bsln_nmbr as BSLN,
vm.actl_visit_nmbr as VIS_NUM,
vm.eff_dt as EFF_DATE,
av.visit_dt as VIS_DATE, vm.mlstn_type as MILESTN
from visit_milestones vm,
actual_visits av, primary_investigators pi
where vm.proj_id = av.proj_id
and vm.bsln_nmbr = av.bsln_nmbr
and vm.actl_visit_nmbr = av.actl_visit_nmbr
and av.proj_id = pi.proj_id
and vm.proj_id = 10999099
and vm.eff_dt between '01-SEP-2004'
and '30-SEP-2004'
and UPPER(vm.mlstn_type)='MILESTONE ABC')
group by PROJ, SITE, BSLN, VIS_NUM, VIS_DATE))
group by SITE
Help. I cannot figaure out what is wrong with this SQL.
I am trying to display an average cycle time per site.
I end up getting the same result for all sites.
Thanks in advance.
-Cassie
select SITE, AVG(CycleTime) as AVG_CT
from
(select SITE, ROUND(DEC_DATE-VIS_DATE,2) as CycleTime
from
(select PROJ, SITE, BSLN, VIS_NUM,
VIS_DATE,max(EFF_DATE) as DEC_DATE
from
(select vm.proj_id as PROJ,
pi.waes_site_cd as SITE,
vm.bsln_nmbr as BSLN,
vm.actl_visit_nmbr as VIS_NUM,
vm.eff_dt as EFF_DATE,
av.visit_dt as VIS_DATE, vm.mlstn_type as MILESTN
from visit_milestones vm,
actual_visits av, primary_investigators pi
where vm.proj_id = av.proj_id
and vm.bsln_nmbr = av.bsln_nmbr
and vm.actl_visit_nmbr = av.actl_visit_nmbr
and av.proj_id = pi.proj_id
and vm.proj_id = 10999099
and vm.eff_dt between '01-SEP-2004'
and '30-SEP-2004'
and UPPER(vm.mlstn_type)='MILESTONE ABC')
group by PROJ, SITE, BSLN, VIS_NUM, VIS_DATE))
group by SITE