Update record in sql table with a sum of values from other table

user3578048

Im new to SQL. I have a table employee, it has fields eID and eLoad. In addition i have table ongoing_projects it has pID, eID (those two are primary) and eLoad. Im trying to insert a sum of all eLoads for each employee. I have an idea for pseudocode, but I cannot implement it. Any Ideas? Thank you!

For each eID in table employee
DO
UPDATE `employee` SET eload=(
  SELECT SUM (eload) as eload
  FROM ongoing_projects 
);
user3714582

If I understood It, you would like to do something like:

UPDATE employee e
SET e.eLoad = (SELECT SUM(op.eLoad) FROM ongoing_projects op WHERE op.eID=e.eID);

It updates each row in employees.eLoad column with the sum of the ongoing_projects.eLoad where the ongoing_projects.eID=actual employee eID

Or if you would like to SUM employees.eLoad with the ongoing_projects eLoad then the query may look:

UPDATE employee e
SET e.eLoad = e.eLoad + (SELECT SUM(op.eLoad) FROM ongoing_projects op WHERE op.eID=e.eID);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Update table with values from other table

From Dev

Update table with values from other table

From Dev

Update a table based on values from a other table

From Dev

SQL SUM() All with check from other table

From Dev

SQL statement (for loop) with SUM from other table

From Dev

update table with values from 2 other tables

From Dev

update value from a table if from other two table values match

From Dev

Update SQL Server Table Row by row from values of other table with joins

From Dev

SQL sum values from the same table

From Dev

SQL - Update table values from values in another table

From Dev

update values of sql table using the values from the same table

From Dev

sql query - update fields in existing with record values in the same table

From Dev

Update values in the SQL table from a file

From Dev

How to update SQL table from other table when they are on different servers

From Dev

How can I insert values from SELECT SUM into other table?

From Dev

How can I insert values from SELECT SUM into other table?

From Dev

Select record from table with not in other table

From Dev

Select record from table with not in other table

From Dev

Select from table if other table points to record

From Dev

Update sql table daily with values from another table

From Dev

SQL - Update table1 values from table2

From Dev

Update record in table from another table

From Dev

Update all rows on table based on value from other table that gets multiple values from third table

From Dev

SQL Server - update underlying table Record from View AFTER INSERT

From Dev

Update sum from another table

From Dev

SQL Join table and SUM values

From Dev

MYSQL Update Column with higher values from other table

From Dev

Update/insert table with other table in SQL

From Dev

Sum values from a table in a loop

Related Related

  1. 1

    Update table with values from other table

  2. 2

    Update table with values from other table

  3. 3

    Update a table based on values from a other table

  4. 4

    SQL SUM() All with check from other table

  5. 5

    SQL statement (for loop) with SUM from other table

  6. 6

    update table with values from 2 other tables

  7. 7

    update value from a table if from other two table values match

  8. 8

    Update SQL Server Table Row by row from values of other table with joins

  9. 9

    SQL sum values from the same table

  10. 10

    SQL - Update table values from values in another table

  11. 11

    update values of sql table using the values from the same table

  12. 12

    sql query - update fields in existing with record values in the same table

  13. 13

    Update values in the SQL table from a file

  14. 14

    How to update SQL table from other table when they are on different servers

  15. 15

    How can I insert values from SELECT SUM into other table?

  16. 16

    How can I insert values from SELECT SUM into other table?

  17. 17

    Select record from table with not in other table

  18. 18

    Select record from table with not in other table

  19. 19

    Select from table if other table points to record

  20. 20

    Update sql table daily with values from another table

  21. 21

    SQL - Update table1 values from table2

  22. 22

    Update record in table from another table

  23. 23

    Update all rows on table based on value from other table that gets multiple values from third table

  24. 24

    SQL Server - update underlying table Record from View AFTER INSERT

  25. 25

    Update sum from another table

  26. 26

    SQL Join table and SUM values

  27. 27

    MYSQL Update Column with higher values from other table

  28. 28

    Update/insert table with other table in SQL

  29. 29

    Sum values from a table in a loop

HotTag

Archive