-3

我有 4 个选择表与Union All这些表的 connect0r 相同。

Select [] from [a] inner join [b] on a.[] = b.[]
where []

Union All

Select [] from [a] inner join [b] on a.[] = b.[]
where []

Union All

Select [] from [a] inner join [b] on a.[] = b.[]
where []

Union All

Select [] from [a] inner join [b] on a.[] = b.[]
where []

我已经尝试order by [a] asc在最后一行或每一select行中制作,但它仍然不起作用并成为错误。

4

2 回答 2

2

首先select,您必须有带别名的列A

Select col1 as a [...] from [a] inner join [b] on a.[] = b.[] where []    
Union All   
Select [] from [a] inner join [b] on a.[] = b.[] where []    
Union All    
Select [] from [a] inner join [b] on a.[] = b.[] where []    
Union All    
Select [] from [a] inner join [b] on a.[] = b.[] where []
order by a
于 2013-07-12T07:42:56.090 回答
0

您只需将 ORDER BY 子句放在语句的末尾,引用首先选择的列名/别名。

例如。

SELECT a,b customName
FROM T1 
WHERE a = 'yourFilter'
UNION ALL
SELECT foo1,foo2 
FROM T2 
WHERE foo2 IN ('otherFilter','otherFilter2')
ORDER BY customName DESC, a
于 2013-07-12T07:44:57.793 回答