Recursive COUNT Query (SQL Server)
Posted
by Cosmo
on Stack Overflow
See other posts from Stack Overflow
or by Cosmo
Published on 2010-05-19T16:38:17Z
Indexed on
2010/05/19
16:50 UTC
Read the original article
Hit count: 249
Hello Guys!
I've two MS SQL tables: Category, Question. Each Question is assigned to exactly one Category. One Category may have many subcategories.
Category
- Id : bigint (PK)
- Name : nvarchar(255)
- AcceptQuestions : bit
- IdParent : bigint (FK)
Question
- Id : bigint (PK)
- Title : nvarchar(255) ...
- IdCategory : bigint (FK)
How do I recursively count all Questions for a given Category (including questions in subcategories). I've tried it already based on several tutorials but still can't figure it out :(
© Stack Overflow or respective owner