Skip to content
Advertisement

how to divide the amount for each record on specific condition

I have a table let’s assume X and I want to join it to another table Y

this the content of X

table Y

If I made a relationship between X & Y tables the amount it will be duplicated, so if I used sum function the total will be wrong

I decided to divide the amount between the stores for each ID for example the amount for ID 200 will be like this

when I use sum function the result will return to its original value 45

how can I do this calculation in SQL code?

Advertisement

Answer

Hmmm . . . If I understand correctly, you want to allocate the full value over multiple rows. Use window functions:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement