繁体   English   中英

使用选择 Postgres 插入值

[英]Insert values with select Postgres

我需要做一个insert,但是之前我需要将insert的值与其他表进行比较,这样我也可以插入其他表的值,在我要插入的当前表中:

在此处输入图片说明

我不知道如何编写插入语法

Insert into TABLE_3 (code, value, description)
values 123, 20000, teste

考虑insert ... select ...语法。 values()列表对此很方便。

insert into table_3(code, value, desription, subscription, value_percent, total_value)
select
    v.code,
    v.value,
    v.description,
    t1.subscription,
    t2.value_percent,
    v.value * t2.value_percent / 100.0 total_value
from (values (123, 20000, 'teste')) v(code, value, description)
inner join table_1 t1 on t1.code = v.code
inner join table_2 t2 on t2.subscription = t1.subscription

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM