SQL Server 쿼리에 지정된 ID의 모든 자식을 얻는 방법 :내가 SQL Server 데이터베이스에 두 개의 테이블이
category(
itemid,
parentid
)
ArticleAssignedCategories(
categid,
artid
)
categid
내가 artids
의 수를 얻으려면 itemid
의 외래 키 그 자식은 주어진 itemid
(어린이는 parentid
이 주어진 범주를 의미합니다)
예를 들어, category
는 3, 4, 5의 자녀 (3,1), (4,1) (5,3)입니다했다
모든 대하여 itemid = 1
경우 테이블에서 1
사람은 쓰기 위해 도와 줄 수 좋은 쿼리?
사용하여 수행 할 수 있습니다 도움이 될 수 있기를 바랍니다. http://stackoverflow.com/questions/12858567/how-to-get-all-children-and-itself-from-hierarchical-data-with-cte-in-sql-server –