从数据库中选择相册的名称和数量(Selecting the name and the number of albums from a database)
我有以下数据库( http://blog.xojo.com/wp-content/uploads/2016/04/ChinookDatabaseSchema1.1.png ),我想选择艺术家的名字和艺术家的专辑数量已记录,但每次运行代码时,它都会显示第一个名称和专辑总数。
这是我的代码:
SELECT Name, count(*) FROM album INNER JOIN artist ON album.ArtistId = artist.ArtistId;I have the following database (http://blog.xojo.com/wp-content/uploads/2016/04/ChinookDatabaseSchema1.1.png) and I would like to select the name of the artist and the number of albums the artist has recorded, but every time i run the code, it displays the 1st name and the total number of albums.
This is my code:
SELECT Name, count(*) FROM album INNER JOIN artist ON album.ArtistId = artist.ArtistId;最满意答案
使用Group By
SELECT Name, count(*) FROM album INNER JOIN artist ON album.ArtistId = artist.ArtistId; GROUP BY NameUse Group By
SELECT Name, count(*) FROM album INNER JOIN artist ON album.ArtistId = artist.ArtistId; GROUP BY Name更多推荐
发布评论