If I have the following SQL database, how can I get this information?
Trying to learn TSQL once and for all :P
I'd like to select a list of Productos ordered by Category.
EDIT:
Here is the query I created with your help, but it's still not showing exactly what I'd like:
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
Result:
So it would show:
Product Name, Product count, that has category X
Product Name, Product count, that has category X
Produc开发者_高级运维t Name, Product count, that has category X
Product Name, Product count, that has category X
out the back of my head, and assuming that the number of records in Proveedor is the Count:
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
Please don't shoot me if it has a few errors.
精彩评论