0

suppose I have this database :

Name         Price
447          1500
501          1000
574          1510
574          680
574          400
574          890

I want the end result is like this :

Name         Price
447          1500
501          1000
574          3480
574          3480
574          3480
574          3480

Where 3480 is the sum result of price with name 574. I saw some solutions with partition, but require a definitive id, while mine don't have it. I tried it too with cross join but mine can't work since it sums all not separately based its name. Any help appreciated.

Rayan Suryadikara
  • 237
  • 1
  • 3
  • 17

1 Answers1

1

You can do this with a correlated subquery:

select t.name,
       (select sum(t2.price) from t t2 where t2.name = t.name) as price
from t;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786