sql server - Get an individual sum amount based on currency in T-SQL -


so have table follows

person      currency      price steve       gbp           10 steve       gbp           20 steve       eur           30 dave        usd           10 dave        usd           10 dave        eur           20 john        eur           30 john        gbp           20 john        usd           30 

i want have output view sums each client based on how have spent currency so:

person      currency       amount steve       gbp            30 steve       eur            30 dave        usd            20 dave        eur            30 john        eur            30 john        gbp            20 john        usd            30 

what have tried

so far have tried query this:

select   person, currency, sum(price) amount  table group currency 

the logic of being order them based on currencies has not worked, telling me need add more group clause. missing?

update

so far comments have been great left out small detail.

the currency orignially pair i.e usd/gbp , in order select 1 need using left function

example:

left(currencypair,3) currency, 

which causing list this:

aud gbp eur usd usd usd 

try this,

select
person, currency, sum(price) totalsumofcurrencybyperson

from table group person,left(currencypair,3)

the first problem have grouped currency which, there 4 types give sum of gbp, aud, usd , euro. need add layer of grouping query in order sum each currency person.

the second problem need group select "left(currencypair,3)".

hope helps!


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -