从数据库中选择相册的名称和数量(Selecting the name and the number of albums from a database)

编程入门 行业动态 更新时间:2024-10-28 09:13:27
数据库中选择相册的名称和数量(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 Name

Use Group By

SELECT Name, count(*) FROM album INNER JOIN artist ON album.ArtistId = artist.ArtistId; GROUP BY Name

更多推荐

本文发布于:2023-04-27 21:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1328626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   数量   名称   相册   database

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!