Last active
August 29, 2015 14:24
-
-
Save osya/b0817f05cb5cbb0757a9 to your computer and use it in GitHub Desktop.
Подсчет количества подчиненных узлов 1-го уровня в дереве #SQL
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 [mis-dm].[DM].[D_TERRITORY] | |
SET ChildrenCount = (SELECT COUNT(t2.TERRITORY_ID) ChildrenCount | |
FROM DM.D_TERRITORY t1 | |
LEFT JOIN DM.D_TERRITORY t2 ON t2.PARENT_ID = t1.TERRITORY_ID | |
WHERE t1.TERRITORY_ID = [mis-dm].[DM].[D_TERRITORY].TERRITORY_ID | |
GROUP BY t1.TERRITORY_ID | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment