我正在尝试显示AnnualBudget中的最小值,这是我到目前为止所做的代码:
SELECT WARD.HospitalCode,
HOSPITAL.HospitalCode Name,
WardNo,
AnnualBudget
FROM WARD,
HOSPITAL
WHERE (AnnualBudget) =
(SELECT AnnualBudget
FROM WARD
WHERE AnnualBudget =
(SELECT MIN(AnnualBudget)
FROM WARD
WHERE AnnualBudget >
(SELECT MIN(AnnualBudget)
FROM WARD
)
)
);
然而,不是选择最小值而是实际选择最大值,有人可以帮忙吗?
答案 0 :(得分:0)
以下查询将为您提供高于min
的内容select min(annualbudget)
from ward
where annualbudget > (
select min(annualbudget)
from ward
)
如果你想要分钟,试试这个:这些天我没有太多的oracle,但它应该有效)
select (stuff)
from ward w
join hospital h on h.hospitalId = w.hostpitalId
where w.annualbudget = (select min(annualbudget) from ward)
答案 1 :(得分:0)
这不应该更像这样吗?
SELECT W.HospitalCode, H.HospitalCode, Name, WardNo, AnnualBudget
FROM WARD W, HOSPITAL H
WHERE W.HospitalCode = H.HospitalCode
and W.AnnualBudget = (Select MIN(AnnualBudget) FROM WARD W2
WHERE W2.HospitalCode = W.HospitalCode)
我认为WARD中的医院代码是外键,你希望每家医院的病房预算最低,对吗?