如何合并大查询中的表
how to union the tables in big query
select a,b,c from(SELECT max(modifiedtime) a FROM tabl1 ),
(SELECT max(modifiedtime) b FROM tabl2 ),
(SELECT max(modifiedtime) c FROM tabl3 ) ;
工作正常但是...输出就像...
行
a b c
1 1421906942814 null null
2 null 1421906942814 null
3 null null 1421906942817
但我想打印像
这样的数据
a b c
1421906942814 1421906942814 1421906942817
怎么做...
尝试
SELECT
(SELECT max(modifiedtime)
FROM tabl1) a,
(SELECT max(modifiedtime)
FROM tabl2) b,
(SELECT max(modifiedtime)
FROM tabl3) c;
据我所知,您需要使用虚拟密钥(即使它是常量)才能对其执行 JOIN。
这个有效:
SELECT t1.value,
t2.value,
t3.value
FROM
(SELECT 1 AS dummykey,
'max1' AS value) t1
JOIN
(SELECT 1 AS dummykey,
'max2' AS value) t2 ON t1.dummykey=t2.dummykey
JOIN
(SELECT 1 AS dummykey,
'max3' AS value) t3 ON t1.dummykey=t3.dummykey
我会在它们之间进行 CROSS JOIN:
SELECT * FROM
(SELECT max(modifiedtime) FROM tabl1) a
CROSS JOIN
(SELECT max(modifiedtime) FROM tabl2) b
CROSS JOIN
(SELECT max(modifiedtime) FROM tabl3) c;
select a,b,c from(SELECT max(modifiedtime) a FROM tabl1 ),
(SELECT max(modifiedtime) b FROM tabl2 ),
(SELECT max(modifiedtime) c FROM tabl3 ) ;
工作正常但是...输出就像... 行
a b c
1 1421906942814 null null
2 null 1421906942814 null
3 null null 1421906942817
但我想打印像
这样的数据 a b c
1421906942814 1421906942814 1421906942817
怎么做...
尝试
SELECT
(SELECT max(modifiedtime)
FROM tabl1) a,
(SELECT max(modifiedtime)
FROM tabl2) b,
(SELECT max(modifiedtime)
FROM tabl3) c;
据我所知,您需要使用虚拟密钥(即使它是常量)才能对其执行 JOIN。
这个有效:
SELECT t1.value,
t2.value,
t3.value
FROM
(SELECT 1 AS dummykey,
'max1' AS value) t1
JOIN
(SELECT 1 AS dummykey,
'max2' AS value) t2 ON t1.dummykey=t2.dummykey
JOIN
(SELECT 1 AS dummykey,
'max3' AS value) t3 ON t1.dummykey=t3.dummykey
我会在它们之间进行 CROSS JOIN:
SELECT * FROM
(SELECT max(modifiedtime) FROM tabl1) a
CROSS JOIN
(SELECT max(modifiedtime) FROM tabl2) b
CROSS JOIN
(SELECT max(modifiedtime) FROM tabl3) c;