多分类产品查询

分类是无限级的

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

需求:

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

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))
)

原文地址:https://www.cnblogs.com/wdfrog/p/1776195.html