0

SQL 代码:

select * from pay_dedn_mst_st where pf_no='A044643' AND PAY_DATE='06-FEB-2013';

PF_NO   PAY_DATE  DEDN_MST_CODE DEDN_MST_AMOUNT CRNT_INST_NBR TOTAL_INST_NBR USERID    LAST_UPDA
------- --------- ------------- --------------- ------------- -------------- --------- ---------
A044643 06-FEB-13           122             100                              PN        07-MAR-13

A044643 06-FEB-13            21             444            21             60 PN        07-MAR-13

A044643 06-FEB-13            21            6667            21             60 PN        07-MAR-13

A044643 06-FEB-13             4             300             2             10 PN        07-MAR-13

A044643 06-FEB-13            61            1340             4              5 PN        07-MAR-13

我有 2 行相同的 DEDN_MST_CODE,即 21。我如何更新 DEDN_MST_CODE 并将其设置为 47,以便在 DEDN_MST_CODE 21 中获得最少的 DEDN_MST_AMOUNT。

4

1 回答 1

0
UPDATE pay_dedn_mst_st
SET DEDN_MST_CODE = 47
FROM (SELECT MIN(DEDN_MST_AMOUNT) as amount
      FROM pay_dedn_mst_st
      WHERE pf_no='A044643' AND PAY_DATE='06-FEB-2013'
        AND DEDN_MST_CODE = 21) t
WHERE pf_no='A044643' AND PAY_DATE='06-FEB-2013'
  AND DEDN_MST_CODE = 21 AND DEDN_MST_AMOUNT = t.amount
于 2013-05-07T15:30:44.420 回答