[英]Join few column into one table
如何將它加入一個表?
select xxx.* from
(
(select a from x where a in (q)) as kk,
(select a from x where a in (w)) as hh,
(select a from x where a in (e)) as gg
) xxx
我想得到:
gg|hh|kk
---------
1 |2 |3
(結果僅是示例)
您要執行的操作稱為樞軸。 這是您的數據的簡單示例:
WITH cte AS (
SELECT xxx.* from
(
(select 1 as val, 'a' AS id) UNION ALL
(select 2 as val, 'b' AS id) UNION ALL
(select 3 as val, 'c' AS id)
) AS xxx
)
SELECT *
FROM cte AS p
PIVOT (MAX(val) FOR id IN ([a], [b], [c])) AS pvt
好的,您沒有提到的是您發布的查詢無效(您有多余的括號)。 以下是我認為您想要的答案:
從第一個例子...
select *
from
(select 1 as a) as table1,
(select 2 as b) as table2,
(select 3 as c) as table3;
如果您有多列:
select table1.aa as a, table2.bb as b, table3.cc as c
from
(select 1 as aa, 11 as aaa) as table1,
(select 2 as bb, 22 as bbb) as table2,
(select 3 as cc, 33 as ccc) as table3;
兩者都給:
a b c
1 2 3
這個怎么樣?
select xxx.*
from (select 1 as a, 2 as b, 3 as c) as xxx;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.