尝试一劳永逸地学习TSQL:P
我想选择按类别订购的Productos列表。
修改
以下是我在您的帮助下创建的查询,但它仍未显示我想要的内容:
select p.Nombre as Nombre, c.Nombre as Categoria FROM Producto as p
inner join Subcategoria as s ON p.IDSubcategoria = s.ID
inner join Categoria as c on s.IDCategoria = c.ID
group by p.Nombre, c.Nombre
order by p.Nombre
结果:
所以它会显示:
Product Name, Product count, that has category X
Product Name, Product count, that has category X
Product Name, Product count, that has category X
Product Name, Product count, that has category X
答案 0 :(得分:1)
出了我的脑袋,假设Proveedor中的记录数是计数:
SELECT p.Nombre as Name, COUNT(pr.*), c.Nombre as Category FROM Producto as p
INNER JOIN Subcategoria as s ON p.IDSubcategoria = s.ID
INNER JOIN Categoria as c on s.IDCategoria = c.ID
INNER JOIN Proveedor as pr ON p.IDProveedor = pr.ID
GROUP BY p.Nombre, c.Nombre
ORDER BY p.Nombre
如果有一些错误,请不要开枪。