开发者

Sql sum and show result in many column

开发者 https://www.devze.com 2023-02-15 17:38 出处:网络
If I have a table look like in this pag开发者_如何学运维e and I wanna sum the orderPrice by each customer.

If I have a table look like in this pag开发者_如何学运维e and I wanna sum the orderPrice by each customer. Then I wanna show the result show in one row look like this. How can I write the query.

Ps. Sorry for show everything on web.


Since you did not put any restrictions on how that information should be produced, you can do the following:

Select Sum( Case When Customer = 'Hansen' Then OrderPrice End ) As sumHansen
    , Sum( Case When Customer = 'Nilsen' Then OrderPrice End ) As sumNilsen
    , Sum( Case When Customer = 'Jensen' Then OrderPrice End ) As sumJensen
From CustomerTotals


If your'e using SQL Server you can use PIVOT statement.

0

精彩评论

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

关注公众号