结果表mysql中两行的总和

时间:2017-04-30 23:23:54

标签: mysql sum rows

我想从结果查询中获取两行的总和。我试过这段代码,但似乎没有用。但是,如果我删除它有效,但没有给予总计。

#If group member is a group grab its info
if($_.objectClass -eq "group"){
    #Do your stuff with the data in here
   $GroupName = $_.Name
   $GroupGUID = $_.objectGUID
}

1 个答案:

答案 0 :(得分:0)

一个问题(至少)是您无法在定义它们的同一PP_*ENUM*中重复使用别名。所以:

SELECT

我还建议你包括所有插入的列。这是一个很好的习惯。所以:

INSERT INTO totaltransportcost
    select year(date) as y, month(date) as m, sum(FuelCost) as fc, 
           SUM(OtherExpenses) as oe,
           SUM(FuelCost + OtherExpenses) as tot
    from turn
    group by year(date), month(date);