-2

我有这种表结构

-----------------------------------------------------------------
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

谢谢

4

1 回答 1

1
SELECT  t.*,
        COALESCE(Monday, 0) +
        COALESCE(Tuesday, 0) +
        COALESCE(Wednesday, 0) +
        COALESCE(Thursday, 0) +
        COALESCE(Friday, 0) AS total
FROM    mytable t
于 2013-05-21T10:07:57.293 回答