所以我有这个 MySQL 5.0.24 表
select state, county, population from state_pops order by state, county;
产量
Arizona Yapavai 4
Arizona Pueblo 5
Arizona Pinal 8
Arizona Maricopa 13
Michigan Lawson 3
Michigan Maple 4
Michigan Appleton 8
Texas Richmond 5
Texas Dupree 7
Texas Brighton 10
我需要确定哪个是每个州人口最多的县。
select state, county, max( population) from state_pops group by state order by state;
产量
Arizona Maricopa 13
Michigan Appleton 8
Texas Brighton 10
简单的。但是现在我需要以某种方式标记每个州人口最多的县,同时列出所有州的所有县,就像这样
Arizona Yapavai 4 NO
Arizona Pueblo 5 NO
Arizona Pinal 8 NO
Arizona Maricopa 13 YES
Michigan Lawson 3 NO
Michigan Maple 4 NO
Michigan Appleton 8 YES
Texas Richmond 5 NO
Texas Dupree 7 NO
Texas Brighton 10 YES
所以我需要以某种方式得出一个列,也许是某种形式的 CASE..WHEN 有什么想法吗?
TIA,
仍在学习的史蒂夫