postgre sql 批量更新 根据另一张表中的yxj优先级列 去更新另一个表中的yxj优先级列

SELECT
    c_bh,
    c_zdmc,
    ROW_NUMBER () OVER (
        PARTITION BY c_zdmc
        ORDER BY
            n_zxd DESC
    ) AS yxj2
FROM
    db_jcwzsj.t_zjzdyxj;

UPDATE db_jcwzsj.t_zjzdyxj AS P
SET n_yxj = A .yxj2
FROM
    (
        SELECT
            c_bh,
            c_zdmc,
            ROW_NUMBER () OVER (
                PARTITION BY c_zdmc
                ORDER BY
                    n_zxd DESC
            ) AS yxj2
        FROM
            db_jcwzsj.t_zjzdyxj
    ) AS A
WHERE
    P .c_bh = A .c_bh;

postgresql如果查询出的数据为空,则设为0的方法

select COALESCE(b.price, 0) as price from fruit_sale b

postgresql多表联合批量更新

update table_p as p 
set p_name = a.name,p_user = a.user_id,p_type = 'P02'
from (
select x.user_id,x.name,x.p_id from table_u x
join table_p y on x.p_id = y.p_id
) as a where p.p_id = a.p_id;
 

猜你喜欢

转载自blog.csdn.net/weixin_40803329/article/details/81741706
今日推荐