-1

我想得到联合,但想用不同的别名显示一列两次。例如

Select a as first from table1 
union 
select a as second from table1

它首先显示为输出。

但我想同时展示第一和第二。在 MSSQL 中如何实现?

4

3 回答 3

2

Union 将两个查询的结果合并到一组列中。没有办法让列名更改一半。我能想到的最接近的是

select a as first
, null as second 
from table1 

union all 

select null as first
, a as second 
from table1
于 2013-07-22T12:26:10.287 回答
1

您将拥有所有行union all

Select a as first from table1 
union all 
select a as second from table1
于 2013-07-22T12:10:11.670 回答
1

如果我做对了:

Select a as first,a as second from table1 
于 2013-07-22T12:14:15.993 回答