2016-10-20 29 views
0
Table A 
---------------- 
Date index 
------------------ 
2016-10-20 2.3 
2016-10-21 2.8 
-------  --- 
-------  --- 


Table B: 
-------- 
Code Life_completed 
A  5 
b  6 

实际查询:SQL:子查询问题

select *,(select sum(index) 
      from table1 
      where date between current_date +3 AND current_date 
     ) as Index 
from table b 

预计查询: 我们能用current_date +Life_completed

我们使用Vertica的数据库取代CURRENT_DATE +3 ..

请在这里帮助..

+0

请给数据库标记 – NzGuy

+0

您是否尝试过替换它?它应该工作(当然你必须切换在两者之间使用的值) – dnoeth

+0

@dnoeth:是的,我试过..获取一些错误.. select/gby/oby中的相关子查询列不受支持 –

回答

0

此相关子查询与左乔相同加上总和:

select b.Code, b.Life_completed, 
    sum(a.index) as Index 
from tableB b 
left join tableA as a 
    on a.date between current_date AND current_date + B.life_completed