遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

多分类产品查询

分类是无限级的

产品跟分类的关系是多对多

需求:

查询一组分类下的全部产品,注意给定的分类编号列表中的分类,可能包括下一级分类

Select distinct P.ProductId,p.Name From Product p
left join ProductTradeClassMap cmap
on p.ProductId=cmap.ProductId
where
P.IsDeleted=0 And
cmap.ClassId in(
 Select distinct  c.ClassId From
  (
    Select ClassId,Code From TradeClass Where ClassId in(4,7,6,8,2,156)
  ) as t
  inner join TradeClass c
 ON t.Code=Left(c.Code,Len(t.Code))
)

posted on 2010-07-13 09:02  遗忘海岸  阅读(309)  评论(0编辑  收藏  举报