更新时间:2023-11-25 08:07:58
您可以在两个sql语句中完成此操作.
以下查询将获取您的所有父类别.
Hi,
You can do it in two sql statements.
The below query will get all your parent categories.
Select id, name from categories where parentid is NULL
然后,当用户选择一个类别时,您便知道其ID,因此只需选择所有父类别与所选类别匹配的子类别.
Then when the user selects a category you know its Id, so then you just select all the child categories which have a parent category matching the selected category.
//Pass in parameter @ParentId which matches the Category clicked.
Select id, name from categories where parentid = @ParentId