两侧,我需要通过city
订购union
查询的两面:订购工会
select * from(select top(1)city, len(city) from Station
where len(city) = (select min(len(d.city)) from Station d) order by city) as a
union all select * from (select top(1) city, LEN(city) from Station
where len(city) = (select max(len(f.city)) from station f) order by city) as b
我需要订购两侧,因为如果我有相同长度的两个城市,然后我需要得到第一个按字母顺序,如果我把order by
在整个查询结束它不会做我想要的,如果你有另一种方式做到这一点,我将不胜感激的建议..
当我运行这个查询我收到此错误:
Msg 8155, Level 16, State 2, Line 3
No column name was specified for column 2 of 'a'.
Msg 8155, Level 16, State 2, Line 4
No column name was specified for column 2 of 'b'.
我该怎么办?
我意识到,我应该把名字列LEN(市),这是whay错误正在发生:) – AlexGH