按天更新Postgresql中的兴趣值

问题描述 投票:0回答:1

我在这里至少需要一些提示,以帮助了解如何在Firebird中使用此查询到PostgreSQL。关于每天的兴趣自动更新。一直以这种方式工作,但是现在我们正在迁移,尽管我尝试了许多不同的方式,但找不到解决方案。感谢您的关注。

execute block as 
declare variable id Integer;
begin 
for select BILL_ID from BILLS into :id do update BILLS set BILL_INTEREST_VALUE = 
TRUNC(replace(((((BILL_VALUE * BILL_PERCENT) / 100) / 30) * datediff(day, BILL_INTEREST_DATE, current_date)),',','.'), 2)where BILL_ID = :id and BILL_CLIENT_ID="+id+"
and datediff(day, BILL_INTEREST_DATE, current_date) >=  BILL_DAYS_INTEREST and 
BILL_VALUE > 0.00;
end;

java postgresql firebird
1个回答
0
投票

据我所知,我不明白为什么要使用过程语言,所以可以用一条没有循环的UPDATE语句替换它:

UPDATE BILLS 
  SET bill_interest_value = trunc( (((BILL_VALUE * BILL_PERCENT) / 100) / 30) * (current_date - bill_interest_date))
WHERE bill_id IN (SELECT bill_id FROM bills)
  AND bill_client_id = ?
  AND current_date - bill_interest_date >=  bill_days_interest 
  AND bill_value > 0.00;

以上假设bill_interest_datedate列(不是时间戳)

© www.soinside.com 2019 - 2024. All rights reserved.