SQL输出将列转换为行

时间:2019-07-17 07:54:20

标签: mysql sql

我正在运行以下SQL查询:

select distinct col + "abc" value1, col+ "xyz" value2
from table_name
where col = "1234567890"

这将输出返回为:

value1        value2
1234567890abc 1234567890xyz

但是我希望输出为:

value
1234567890abc
1234567890xyz

我该怎么做?

2 个答案:

答案 0 :(得分:1)

使用union all

select distinct col + "abc" value
from table_name
where col = "1234567890"
union all
select distinct col+ "xyz" 
from table_name
where col = "1234567890"

答案 1 :(得分:0)

使用concat并全部合并

select concat(col, 'abc') value1
from table_name
where col = '1234567890'
union all
select concat(col, 'xyz')
from table_name
where col = '1234567890'