开发者

Multiply 2 columns in sql and to sum all the results using SQL

I write a query to multiply to colums now i would like 开发者_如何学Pythonto sum up the result that i am getting can any one give me an idea

this is what i wrote

select Rate,Qty,(Rate*Qty) as result from tblName

I will get result say for example 40 90 now i would like to sum these results


Original Answer

select Sum(Rate) as Rate, Sum(Qty) as Qty, Sum(Rate*Qty) as Result from tblName

EDIT - Try this..

select 
     0 as TotalRow, 
     Rate,
     Qty,
    (Rate*Qty) as Result 
from tblName

UNION ALL

select 
     1 as TotalRow,
     Sum(Rate) as Rate, 
     Sum(Qty) as Qty, 
     Sum(Rate*Qty) as Result 
 from tblName

Order By TotalRow


SELECT SUM(Rate*Qty) as Result
FROM tblName
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜