查询语句:
select b.id,
b.ios,
b.dept,
b.ward,
c.beds,
count(a.patient_id) used
from pats_in_hospital a,
(select substr(a.dept_code, 3, 6) id,
decode(a.internal_or_sergery, 0, '内科', 1, '外科') ios,
b.dept_name dept,
a.dept_name ward
from dept_dict a,
(select dept_code, dept_name
from dept_dict
where length(trim(dept_code)) = 4) b
where substr(a.dept_code, 3, 4) = b.dept_code) b,
(select dept_code, count(*) beds from bed_rec group by dept_code) c
where b.id = a.dept_code
and c.dept_code = a.dept_code
group by b.id, b.ios, b.dept,b.ward, c.beds
order by id;求教模型的实现, 最佳答案