这个是父类
select c.Total,d.ID,d.CateogryName from Sys_Category d inner join(
select Sum(b.Num) as Total,a.ID from Sys_Category a inner join (
select count(*) as Num,Category_ID from corp_trade Group by Cateogry_ID) b
on a.ID = b.Category_ID or a.Parent_ID=b.Category_ID group by a.ID ) c
on d.ID=c.ID
子类
select a.ID,a.CateogryName,a.Parent_ID,b.Num from Sys_Category a inner join (
select count(*) as Num,Category_ID from corp_trade Group by Cateogry_ID) b
on a.ID=b.Cateogry_ID where a.Parent_ID!=0
在asp.net中填充在一个DataSet中。
然后 ds.Tables[0].ChildRelations.Add("Relation", ds.Tables[0].Columns["ID"], ds.Tables[1].Columns["Parent_ID"]);
页面上用两个嵌套的Repeater实现,把ds.Tables[0]绑定在Repeater1上,Repeater2在Repeater1,Repeater2的DataSource='<%# ((System.Data.DataRowView)Container.DataItem).Row.GetChildRows("Relation") %>'
这个应该不会太慢