Postgres sql无法识别B关系。
任何人都知道如何使这个查询有效吗?
UPDATE B SET fator = A.fator
FROM
(select initial_date, end_date,entity_id, sum(fator) fator
from table1
where initial_date>=(select min(data) from iberia.lcs_wyipi_aux_produtividade_incentivos)
and end_date<=(select max(data) from iberia.lcs_wyipi_aux_produtividade_incentivos)
GROUP BY initial_date, end_date, entity_id) A JOIN table2 B on
A.entity_id=B.entity_id and B.data>=A.initial_date and B.data<=A.end_date
[错误]错误:关系“b”不存在 第1行:更新B设置fator = A.fator
答案 0 :(得分:0)
如果您要更新table2
,则无需将“from”表加入其中。此外,如果在B
关键字后面提到表格,则应设置别名UPDATE
。
UPDATE table2 as B SET fator = A.fator
FROM (
select initial_date, end_date,entity_id, sum(fator) fator from table1
where initial_date >= ( select min(data) from iberia.lcs_wyipi_aux_produtividade_incentivos )
and end_date <= ( select max(data) from iberia.lcs_wyipi_aux_produtividade_incentivos )
GROUP BY initial_date, end_date, entity_id
) as A
where B.entity_id = A.entity_id
and B.data >= A.initial_date
and B.data <= A.end_date
;
答案 1 :(得分:0)
我不是100%确定这会有效,但我认为如果你将源包装在子查询中,它会做你想要的:
for ( var i = 1; i < 8; i++ ) {
$( '.row' + i ).mouseenter(function(e){
$( '.row' + i ).addClass('deepskyblue');
}).mouseleave(function(e){
$( '.row' + i ).removeClass('deepskyblue');
}).on('click',function(e){
e.preventDefault();
clickedRow = e.currentTarget.className;
});
}
唯一担心的是,根据您描述的标准,似乎似乎可能加入的子查询可能会产生您尝试在with A as (
select
initial_date, end_date, entity_id, sum(fator) fator
from table1
where
initial_date >= (select min(data)
from iberia.lcs_wyipi_aux_produtividade_incentivos) and
end_date <= (select max(data)
from iberia.lcs_wyipi_aux_produtividade_incentivos)
GROUP BY initial_date, end_date, entity_id
)
UPDATE table2 B
SET fator = A.fator
FROM
A
where
A.entity_id = B.entity_id and
B.data between A.initial_date and A.end_date
中更新的多个值。如果不是这样,那应该可行。如果是,您需要一些方法来缩小要更新的记录。