两个表之间没有公共密钥的乘法

时间:2018-04-21 02:33:53

标签: sql impala

所以我写了一个impala查询,用

计算最大值(价格)
SELECT Max(price) 
FROM 
(select close AS price from tableA) UNION 
(select strike AS price from tableB) AS T1

所以样本输出将是

Max(price)
200

现在我有另一个包含日期和数字的表格,我希望将200乘以与1-16-15相关的数字,因此所需的输出为

Date     num
1-16-15  40
1-17-15  30

40 * 200 = 8000

1 个答案:

答案 0 :(得分:1)

您可以将两个子查询放在FROM子句中,然后乘以:

SELECT Max(cs.price) * n.num
FROM ((select close AS price from tableA)
      UNION ALL
      (select strike AS price from tableB)
     ) cs CROSS JOIN
     (SELECT num
      FROM anothertable
      WHERE date = '2015-01-16'
     ) n;