java - 按天更新 postgresql 中的兴趣值
问题描述
我需要一些帮助,至少是一个提示,关于如何将这个在 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;
解决方案
我不明白为什么使用过程语言,据我所知,这可以替换为没有循环的单个 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) --<< essentially useless
AND bill_client_id = ?
AND current_date - bill_interest_date >= bill_days_interest
AND bill_value > 0.00;
以上假设bill_interest_date
是一date
列(不是时间戳)
推荐阅读
- neo4j - Neo4j Cypher 选择在哪里存在查询
- c++ - 用 C++ 解析 Wavefront .OBJ 文件的 f 元素
- apache-superset - 超集,仅查看已发布的仪表板
- amazon-web-services - DynamoDB 适合高事务应用吗?
- python - 如何从 MATLAB 运行 Python
- javascript - 带有滚动条但没有调整大小选项的 div 溢出
- node.js - nodejs获取所有用户并仅返回用户名称,ID,图像不是所有数据
- javascript - 是否可以将“allDaySlot”选项与 TimelineView fullcalendar 一起使用?
- c# - SQL 数据库未“保存”通过代码 (C#) 添加的信息
- odata - 与 OData V2 关联的 setProperty