求sql语句?
有大类 小类 产品表。怎么查询大类下所有小类,然后所有小类里产品的数据。
显示如下:大类名称 小类名称 产品总数
表结构:
大类表结构为 id name
小类表结构为 id 大类id name
产品表位 小类id 产品名称
写了一个如下:
select t3.ProductBigTypeName,t1.ProductsTypeName, count(t2.ProductsTypeId)
from Base_Gx_ProductsInfo as t2
inner join Base_SmallTypeInfo as t1
on t1.ProductsTypeId = t2.ProductsTypeId
inner join Base_BigTypeInfo as t3
on t1.ProductBigTypeId = t3.ProductBigTypeId
group by t1.ProductsTypeId
提示t3.ProductBigTypeName,t1.ProductsTypeName,无效