0
INSERT INTO Calculations(TOTAL_DAYS_NUMBER) 
select DTE_CHARGE - (
   select min(TIME_REGISTERED)
   from (
      select TIME_REGISTERED from SHIFTING_RECORDS where id=5
      UNION ALL
      select TIME_REGISTERED from MEAL_RECORDS where id=5
      UNION ALL
      SELECT TIME_REGISTERED FROM REGISTRATION WHERE id=5
      )
   ) 
from REGISTRATION
where id=5;

它给了我输出 19 3:28:47.812000000这对我来说是不可能插入到具有整数数据类型的列中的,我只对获取前两位数字感兴趣,即 19。我应该怎么做?

4

1 回答 1

1

使用extract(DAY FROM ...)

INSERT INTO Calculations (TOTAL_DAYS_NUMBER)
SELECT extract(DAY FROM DTE_CHARGE - (
    SELECT min(TIME_REGISTERED) FROM (
        SELECT TIME_REGISTERED
        FROM SHIFTING_RECORDS
        WHERE id = 5

        UNION ALL

        SELECT TIME_REGISTERED
        FROM MEAL_RECORDS
        WHERE id = 5

        UNION ALL

        SELECT TIME_REGISTERED
        FROM REGISTRATION
        WHERE id = 5
    )
))
FROM REGISTRATION
WHERE id = 5;
于 2013-03-10T18:01:53.440 回答