Ошибка в запросе ORA-00918: Столбец определен неоднозначно
select s.shortname
from s_str_orgs s
where s.s_str_org_id = w.s_str_org_s_str_org_id) org_name,
w.s_str_org_s_str_org_id org_id,
(select count(*)
from s_beds b,
s_funcstrs sf
where b.status != 99
and b.s_funcstr_s_funcstr_id = sf.s_funcstr_id
and sf.s_str_org_s_str_org_id = w.s_str_org_s_str_org_id
and b.s_bed_id not in(select bw.s_bed_id from S_BEDOUTS bw where bw.s_bed_id=b.s_bed_id and bw.out_date is null) ) beds,
count(case when w.in_date < to_date('05.03.2022', 'dd.mm.yyyy') and (w.out_date is null or w.out_date >= to_date('05.03.2022', 'dd.mm.yyyy')) then t_med_chrt_id end) sost_bd,
count(case when w.in_date < to_date('05.03.2022', 'dd.mm.yyyy') and (w.out_date is null or w.out_date >= to_date('05.03.2022', 'dd.mm.yyyy')) and floor(months_between(trunc(to_date('05.03.2022', 'dd.mm.yyyy')),b.birthday)/12) > 17 then t_med_chrt_id end) sost_bd_adlt,
count(case when w.in_date < to_date('05.03.2022', 'dd.mm.yyyy') and (w.out_date is null or w.out_date >= to_date('05.03.2022', 'dd.mm.yyyy')) and floor(months_between(trunc(to_date('05.03.2022', 'dd.mm.yyyy')),b.birthday)/12) <= 17 then t_med_chrt_id end) sost_bd_chld,
count(case when w.in_date < to_date('09.03.2022', 'dd.mm.yyyy') and (w.out_date is null or w.out_date>= to_date('09.03.2022', 'dd.mm.yyyy')) then t_med_chrt_id end) sost_ed,
count(case when w.in_date < to_date('09.03.2022', 'dd.mm.yyyy') and (w.out_date is null or w.out_date >= to_date('09.03.2022', 'dd.mm.yyyy')) and floor(months_between(trunc(to_date('09.03.2022', 'dd.mm.yyyy')),b.birthday)/12) > 17 then t_med_chrt_id end) sost_ed_adlt,
count(case when w.in_date < to_date('09.03.2022', 'dd.mm.yyyy') and (w.out_date is null or w.out_date >= to_date('09.03.2022', 'dd.mm.yyyy')) and floor(months_between(trunc(to_date('09.03.2022', 'dd.mm.yyyy')),b.birthday)/12) <= 17 then t_med_chrt_id end) sost_ed_chld,
count(case when w.kind = 'ПОЛОЖЕН' and (w.in_date between to_date('05.03.2022', 'dd.mm.yyyy') and to_date('09.03.2022', 'dd.mm.yyyy')) then t_med_chrt_id end) postup,
count(case when w.kind = 'ПЕРЕВЕДЕН' and w.in_date >= to_date('05.03.2022', 'dd.mm.yyyy') and w.in_date < to_date('09.03.2022', 'dd.mm.yyyy') then t_med_chrt_id end) in_of,
count(case when w.result is null and w.out_date >= to_date('05.03.2022', 'dd.mm.yyyy') and w.out_date < to_date('09.03.2022', 'dd.mm.yyyy') then t_med_chrt_id end) out_of,
count(case when w.result is not null and w.out_date >= to_date('05.03.2022', 'dd.mm.yyyy') and w.out_date < to_date('09.03.2022', 'dd.mm.yyyy') then t_med_chrt_id end) discharge,
count(case when w.result = 'У' and w.out_date >= to_date('05.03.2022', 'dd.mm.yyyy') and w.out_date < to_date('09.03.2022', 'dd.mm.yyyy') then t_med_chrt_id end) dead,
count(case when m.mk_type = 'ПУ' and w.in_date < to_date('05.03.2022', 'dd.mm.yyyy') and (w.out_date is null or w.out_date >= to_date('05.03.2022', 'dd.mm.yyyy')) then t_med_chrt_id end) sost_po_uhodu,
count(case when m.mk_type = 'КС' and (w.out_date is null or w.out_date >= trunc(sysdate,'MI') )then w.t_med_chrt_id end) ssd
from s_dep_ways w,
t_med_chrts m,
t_tlists t,
t_births b ,
( select
r.room room,
w.s_bed_way_id s_bed_way_id,
w.t_med_chrt_id t_med_chrt_id
from s_bed_ways w,
s_beds b,
s_funcstrs r,
s_str_orgs s
where
w.status = 0 and
w.s_bed_s_bed_id = b.s_bed_id and
b.s_funcstr_s_funcstr_id = r.s_funcstr_id
) gg
where w.t_med_chrt_id = m.id
and m.id = t.med_chrt_id
and t.birth_id = b.id(+)
and m.status = 0 -- было != 99
and t.status = 0
and w.kind != 'ПО'
and m.kind = 'ИБ'
and nvl(m.note,'?') != 'ПИБ'
and gg.t_med_chrt_id = t.med_chrt_id
group by w.s_str_org_s_str_org_id
Подскажите пожалуйста в чем ошибка