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;