开发者

how to get sum of this column in sql server

i'm use below query for fetch my data with an ordernumber...

SELECT     Details.Quantity, 
           Details.OrderNumber, 
           Orders.OrderDate, 
           Products.ProductName, 
           Products.UnitPrice ,
           Details.Quantity*Products.UnitPri开发者_运维技巧ce as qprice
FROM       Details 
INNER JOIN Orders 
   ON Details.OrderNumber = Orders.OrderNumber 
INNER JOIN Products 
   ON Details.ProductID = Products.ProductID
where Orders.OrderNumber='14195'

this query give me below result

how to get sum of this column in sql server

now i want give sum of qprice column..

how can i do this??


Like this?

SELECT SUM(Details.Quantity * Products.UnitPrice) AS Amount
FROM Details 
    INNER JOIN Orders ON 
        Details.OrderNumber = Orders.OrderNumber
    INNER JOIN Products ON 
        Details.ProductID = Products.ProductID
WHERE Orders.OrderNumber = '14195'

If you need to have TotalAmount as an extra column to what you already have then:

SELECT    
    Details.Quantity, 
    Details.OrderNumber, 
    Orders.OrderDate,
    Products.ProductName,
    Products.UnitPrice,
    Details.Quantity*Products.UnitPrice as qprice,
    SUM(Details.Quantity*Products.UnitPrice) OVER() TotalAmount
FROM Details 
    INNER JOIN Orders ON 
        Details.OrderNumber = Orders.OrderNumber
    INNER JOIN Products ON 
        Details.ProductID = Products.ProductID
WHERE Orders.OrderNumber = '14195'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜