表tbGg
xh country town village
1 苏仙区 良田镇 良田村
2 苏仙区 良田镇 向阳村
3 苏仙区 邓家塘乡 邓家塘村
4 苏仙区 邓家塘乡 南水界村
1 桂阳县 桥头镇 桥头村
2 桂阳县 桥头镇 白溪村
3 桂阳县 城关镇 城头村
4 桂阳县 城关镇 二龙村
1 永兴县 城关镇 小林村
2 永兴县 城关镇 何家村
3 永兴县 玉泉乡 玉泉村
4 永兴县 玉泉乡 张家村
想对town排序
如果这样写会出错的?
select distinct town from tbjg where country='永兴县' order by xh
这样写,查询结果不正确
select t.town from tbjg t where not exists (select 1 from tbjg where town = t.town and xh < t.xh)
where country='永兴县'
order t.xh
应该怎样写呢?
xh country town village
1 苏仙区 良田镇 良田村
2 苏仙区 良田镇 向阳村
3 苏仙区 邓家塘乡 邓家塘村
4 苏仙区 邓家塘乡 南水界村
1 桂阳县 桥头镇 桥头村
2 桂阳县 桥头镇 白溪村
3 桂阳县 城关镇 城头村
4 桂阳县 城关镇 二龙村
1 永兴县 城关镇 小林村
2 永兴县 城关镇 何家村
3 永兴县 玉泉乡 玉泉村
4 永兴县 玉泉乡 张家村
想对town排序
如果这样写会出错的?
select distinct town from tbjg where country='永兴县' order by xh
这样写,查询结果不正确
select t.town from tbjg t where not exists (select 1 from tbjg where town = t.town and xh < t.xh)
where country='永兴县'
order t.xh
应该怎样写呢?
select distinct town from tbjg where country='永兴县' order by xh
这样写为什么会出错?没错误啊