0

我有以下 SQL 代码,可以很好地将数据行从旧表传输到新表。(在 MySQL 工作台中工作)

INSERT INTO us_compensation.RPBAR 
(ORG_SEC_ID ,
FYE, 
TOTAL_SALARY_PAID , 
OTHER_COMP_PAID ,
TOTAL_BONUS_PAID , 
PERFORMANCE_EQUITY_TIME_VESTING_OPTIONS_TIME_VESTING_STOCK,
TOTAL) 
SELECT DISTINCT
    ORG_SEC_ID,
    FYE,
    TOTAL_SALARY_PAID,
    OTHER_COMP_PAID,
    TOTAL_BONUS_PAID,
    PERFORMANCE_EQUITY + TIME_VESTING_OPTIONS + TIME_VESTING_STOCK,
    TOTAL_SALARY_PAID + OTHER_COMP_PAID + TOTAL_BONUS_PAID
      + PERFORMANCE_EQUITY + TIME_VESTING_OPTIONS + TIME_VESTING_STOCK
FROM
    equilar.realizablepay
group by ORG_SEC_ID
HAVING MAX(FYE);

我需要帮助的是以下内容。旧表中的行会随着新数据的进入而自动更改。但是,新表 (RPBAR) 中的行不会反映新数据。发生的情况是,新表包含来自旧表的旧数据的所有行,并在新表的底部附加进入旧表的新数据。

我希望新表不要将旧数据存储在行中,而是使用旧表中的新数据更新相关行(其中所有相关行都使用新数据更新)。

如何让新表反映旧表行中的新数据,而不是让新表既有旧数据又有新数据?

4

2 回答 2

0

也许您只是想要一个VIEW?

CREATE VIEW us_compensation.RPBAR AS
  SELECT DISTINCT
           ORG_SEC_ID,
           FYE,
           TOTAL_SALARY_PAID,
           OTHER_COMP_PAID,
           TOTAL_BONUS_PAID,
           PERFORMANCE_EQUITY + TIME_VESTING_OPTIONS + TIME_VESTING_STOCK
             AS PERFORMANCE_EQUITY_TIME_VESTING_OPTIONS_TIME_VESTING_STOCK,
           TOTAL_SALARY_PAID + OTHER_COMP_PAID + TOTAL_BONUS_PAID
             + PERFORMANCE_EQUITY + TIME_VESTING_OPTIONS + TIME_VESTING_STOCK
             AS TOTAL
  FROM     equilar.realizablepay
  GROUP BY ORG_SEC_ID
  HAVING   MAX(FYE)
;
于 2012-11-11T22:27:24.390 回答
0
于 2012-11-11T22:22:18.050 回答