开发者

Sql sum and show result in many column

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜