-
-
Save helloris25/ec73e8fefa28de3594899ffc3af65b91 to your computer and use it in GitHub Desktop.
Обновление полей в которых суммы из другой таблицы с условием
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE Table_1 T_1 | |
LEFT JOIN | |
( | |
SELECT | |
id_table1, | |
Sum(CASE | |
WHEN direction = 'one' | |
THEN volume | |
ELSE 0 | |
END) AS sum_one, | |
Sum(CASE | |
WHEN direction = 'two' | |
THEN volume | |
ELSE 0 | |
END) AS sum_two, | |
Sum(CASE | |
WHEN direction = 'three' | |
THEN volume | |
ELSE 0 | |
END) AS sum_three | |
FROM Table_2 | |
GROUP BY id_table1 | |
) T_2 | |
ON T_1.id = T_2.id_table1 | |
SET | |
T_1.total_one = T_2.sum_one, | |
T_1.total_two = T_2.sum_two, | |
T_1.total_three = T_2.sum_three; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment