在Oracle中按行(包括所有列)求和

时间:2013-05-21 10:05:28

标签: sql oracle

我有这种表结构

-----------------------------------------------------------------
ID-Prod | Monday | Tuesday | Wednesday | Thursday | Friday |....
-----------------------------------------------------------------
012        213       879       516         213       435
013        953       837                   361       862
014        123       583       879         519       573
015        963  
016        798

ID-Prod是主键,我想总结每种产品的所有值 例如

---------------------------------------------------------------------------------------
ID-Prod | Monday | Tuesday | Wednesday | Thursday | Friday |....|         Total
---------------------------------------------------------------------------------------
012        213       879       516         213       435           213+879+516+213+435
013        953       837                   361       862                  .....
014        123       583       879         519       573                  .....
015        963  
016        798

由于

1 个答案:

答案 0 :(得分:1)

SELECT  t.*,
        COALESCE(Monday, 0) +
        COALESCE(Tuesday, 0) +
        COALESCE(Wednesday, 0) +
        COALESCE(Thursday, 0) +
        COALESCE(Friday, 0) AS total
FROM    mytable t