How do I code the following algorithm as a SQL query (a
and b
and c
are are tables in my database)
for all a:
case c.column=0
set a.columnname+=b.column1*b.column2
case c.column=1
...
earlier i solved a similar problem by:
UPDATE a
set
a.column= (select SUM(column1) from b where a.column2=b.column2)
but since in is summing a product of two columns i don't think i can do the same. Also the real problem lies with the one to mny relationship a has with c.
relationships:
a one to many b.
b one to one c
lets say A is a table of company data, B is a table of employee data and C tells us if a employee is male or female(just an example not really my problem). Now i need to calculate the total salary given to each employee for each company and store it in a field in the company table.lets say i calculate this differently based on employees gender. Again now there a hundreds of companies and each company has thousands of employees.