如果只需要max(min_postal_code)
,使用下面的語句。
select max(min_postal_code)
from (
select district, min(postal_code) AS min_postal_code
from address
where district is not null and district !="" and postal_code>0
group by district
order by district) t
如果區域名稱與MAX(min_postal_code)
也需要。使用以下語句。
select *
from (select district, min(postal_code) AS min_postal_code
from address
where district is not null and district !="" and postal_code>0
group by district) t
where t.min_postal_code =
(
select max(min_postal_code)
from (select district, min(postal_code) AS min_postal_code
from address
where district is not null and district !="" and postal_code>0
group by district) t2
);
您正在選擇不在「GROUP BY」列表中的「postal_code」列。你應該解決這個問題。 –