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.
精彩评论