Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Update field divide by rowcount

Devel007Nov 5 2018 — edited Nov 5 2018

Hi

I need to update Sales-field in the Table below.

For example Matt has two rows in month 8, so calculation should be Sales/2 (row count) = 50. And Matt has three rows in month 9, calculation is Sales/3 (row count) = 33,33, and so on...

What is the best way to solve this? Merge or just simply Update with group by customer, month, year?

Table

customer              month                year               Sales

Matt                         8                      2018               100

Matt                         8                      2018               100

Matt                         9                      2018               100

Matt                         9                      2018               100

Matt                         9                      2018               100

Simon                      8                      2018               100

Simon                      8                      2018               100

Simon                      9                      2018               100

Simon                      9                      2018               100

End result should look like this after update or merge:

Table

customer              month                year               sales

Matt                         8                      2018               50

Matt                         8                      2018               50

Matt                         9                      2018               33,33

Matt                         9                      2018               33,33

Matt                         9                      2018               33,33

Simon                      8                      2018               50

Simon                      8                      2018               50

Simon                      9                      2018               50

Simon                      9                      2018               50

This post has been answered by Saubhik on Nov 5 2018
Jump to Answer
Comments
Post Details
Added on Nov 5 2018
7 comments
542 views