Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 在postgres中逐行提交_Postgresql - Fatal编程技术网

Postgresql 在postgres中逐行提交

Postgresql 在postgres中逐行提交,postgresql,Postgresql,我在posgres函数中有以下代码: with data_count as( select * from table_t as rrt where rrt.cong_thuc = '' is false order by "level", id) update table_t rp set tong = ( select sum(tong) from table_t t where

我在posgres函数中有以下代码:

with data_count as(
select
    *
from
    table_t as rrt
where
    rrt.cong_thuc = '' is false
order by
    "level",
    id)
update
    table_t rp
set
    tong = (
    select
        sum(tong)
    from
        table_t t
    where
        t.ma_chi_tieu = any(string_to_array(rp.cong_thuc, '+'))),
    eur =(
    select
        sum(eur)
    from
        table_t t
    where
        t.ma_chi_tieu = any(string_to_array(rp.cong_thuc, '+')))
from
    data_count t
where
    rp.id = t.id;
如果一行的
level
>=2,
cong\u-thuc
包含所有
ma\u-chiu-tieu
符号,如果行的
level
1,
cong\u-thuc
为空, 我想更新
tong
eur
所有行中的级别为2,3,4,。。。总而言之,所有行都有
ma_chi_tieu
,另一行包含在
cong_thuc
中,但一次执行都不起作用。我不想从1循环到最高级别。我理解这个查询不会逐行更新。 我的意见在这里

╔════╦═════════════╦═══════════╦═══════╦══════╦══════╗
║ ID ║ Ma_chi_tieu ║ cong_thuc ║ level ║ eur  ║ tong ║
╠════╬═════════════╬═══════════╬═══════╬══════╬══════╣
║  1 ║ R01         ║           ║     1 ║    5 ║    2 ║
║  2 ║ R02         ║           ║     1 ║    6 ║    3 ║
║  3 ║ R11         ║ R01+R02   ║     2 ║ 5000 ║ 6000 ║
║  4 ║ R04         ║           ║     1 ║    7 ║    6 ║
║  5 ║ R05         ║           ║     1 ║    8 ║    7 ║
║  6 ║ R12         ║ R04+R05   ║     2 ║ 1000 ║ 2000 ║
║  7 ║ R13         ║ R12+R11   ║     3 ║16000 ║18000 ║
╚════╩═════════════╩═══════════╩═══════╩══════╩══════╝
这是我的预期输出

╔════╦═════════════╦═══════════╦═══════╦═════╦══════╗
║ ID ║ Ma_chi_tieu ║ cong_thuc ║ level ║ eur ║ tong ║
╠════╬═════════════╬═══════════╬═══════╬═════╬══════╣
║  1 ║ R01         ║           ║     1 ║   5 ║    2 ║
║  2 ║ R02         ║           ║     1 ║   6 ║    3 ║
║  3 ║ R11         ║ R01+R02   ║     2 ║  11 ║    5 ║
║  4 ║ R04         ║           ║     1 ║   7 ║    6 ║
║  5 ║ R05         ║           ║     1 ║   8 ║    7 ║
║  6 ║ R12         ║ R04+R05   ║     2 ║  15 ║   13 ║
║  7 ║ R13         ║ R12+R11   ║     3 ║  26 ║   18 ║
╚════╩═════════════╩═══════════╩═══════╩═════╩══════╝
这是我的输出

╔════╦═════════════╦═══════════╦═══════╦══════╦══════╗
║ ID ║ Ma_chi_tieu ║ cong_thuc ║ level ║ eur  ║ tong ║
╠════╬═════════════╬═══════════╬═══════╬══════╬══════╣
║  1 ║ R01         ║           ║     1 ║    5 ║    2 ║
║  2 ║ R02         ║           ║     1 ║    6 ║    3 ║
║  3 ║ R11         ║ R01+R02   ║     2 ║   11 ║    5 ║
║  4 ║ R04         ║           ║     1 ║    7 ║    6 ║
║  5 ║ R05         ║           ║     1 ║    8 ║    7 ║
║  6 ║ R12         ║ R04+R05   ║     2 ║   15 ║   13 ║
║  7 ║ R13         ║ R12+R11   ║     3 ║ 6000 ║ 8000 ║
╚════╩═════════════╩═══════════╩═══════╩══════╩══════╝

我认为这是真的吗?一旦执行,如何更新此查询?

请(通过单击下面的链接)提出您的问题,并添加一些示例数据和基于该数据的预期输出。有关如何创建美观的文本表的一些提示,请参见。(你的问题-不要在评论中发布代码或附加信息)我按照你的建议进行编辑