在MAX中筛选MAX,求好的SQL语句
idAreaNoAreaNameProvinceIDPostCodeZoneCodeAreaAreaLevelAddWhoAddDate
73999999北京直辖市9华北一级市132010-10-22 00:00:00.000
74110100北京市8华北一级市132010-10-22 00:00:00.000
75110101东城区8华北NULL132010-10-22 00:00:00.000
76110102西城区9华北NULL132010-10-22 00:00:00.000
76110102西城区9华北NULL142010-10-22 00:00:00.000
……
筛选出AddWho = 13 的ProvinceID最大的ID最小行?
[解决办法]
select id, AreaNo, AreaName, max(ProvinceID), PostCode ,ZoneCode, Area ,AreaLevel, AddWhofrom tbwhere AddWho=13 group by
[解决办法]
----写错了忘记加分组条件了。select id, AreaNo, AreaName, max(ProvinceID), PostCode ,ZoneCode, Area ,AreaLevel, AddWhofrom tbwhere AddWho=13 group by id, AreaNo, AreaName, PostCode ,ZoneCode, Area ,AreaLevel, AddWho
[解决办法]
---也可以这样写select id, AreaNo, AreaName, ProvinceID, PostCode ,ZoneCode, Area ,AreaLevel, AddWhofrom tbwhere AddWho=13 group by id, AreaNo, AreaName, PostCode ,ZoneCode, Area ,AreaLevel, AddWhohaving max(provinceID)
[解决办法]
select * from td a where AddWho=13 andid=(select min(id) from td where AddWho=13 and ProvinceID=(select max(ProvinceID) from td where AddWho=13))