我有一个关于创建查询以列出艺术家的基本问题,条件是艺术家有所有格式类型的歌曲,数据库有三个表(检查 ER 图)。
问题是:在所有可能的媒体类型中找到所有带有歌曲的艺术家姓名
并且此处列出了 MediaType:
- MPEG 音频文件
- 受保护的 AAC 音频文件
- 受保护的 MPEG-4 视频文件。.
我试过这个,但我卡在 where 子句中
SELECT a.[Name]
FROM track t INNER JOIN Album alb ON t.AlbumId = alb.AlbumId
INNER JOIN Artist a ON alb.ArtistId = a.ArtistID
INNER JOIN MediaType m ON t.MediaTypeId = m.MediaTypeId
WHERE
这是 SQL DDL 语句的概述:
CREATE TABLE MediaType ( MediaTypeId int(1) PRIMARY KEY, [Name] varchar(30) );
CREATE TABLE Artist(ArtistId int(3), [Name] varchar(100) ); -- LONG CHAR????
CREATE TABLE Album(AlbumId int(3) PRIMARY KEY, Title varchar(100), ArtistId int(3));
CREATE TABLE PlaylistTrack(TrackId int(4) PRIMARY KEY, [Name] varchar(220), AlbumId int(3),
MediaTypeId int(1), GenreId int(2), Composer varchar(220), Miliseconds int(12), Bytes int(12), UnitPrice decimal(8,2)); -- UnitPrice number
这是恢复的数据的概述:艺术家表:
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (1, N'AC/DC');
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (2, N'Accept');
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (3, N'Aerosmith');
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (4, N'Alanis Morissette');
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (5, N'Alice In Chains');
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (6, N'Antônio Carlos Jobim');
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (7, N'Apocalyptica');
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (8, N'Audioslave');
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (9, N'BackBeat');
INSERT INTO `Artist` (`ArtistId`, `Name`) VALUES (10, N'Billy Cobham');
.
.
专辑表:
INSERT INTO `Album` (`AlbumId`, `Title`, `ArtistId`) VALUES (1, N'For Those About To Rock We Salute You', 1);
INSERT INTO `Album` (`AlbumId`, `Title`, `ArtistId`) VALUES (2, N'Balls to the Wall', 2);
INSERT INTO `Album` (`AlbumId`, `Title`, `ArtistId`) VALUES (3, N'Restless and Wild', 2);
INSERT INTO `Album` (`AlbumId`, `Title`, `ArtistId`) VALUES (4, N'Let There Be Rock', 1);
.
.
跟踪表:
INSERT INTO `Track` (`TrackId`, `Name`, `AlbumId`, `MediaTypeId`, `GenreId`, `Composer`, `Milliseconds`, `Bytes`, `UnitPrice`) VALUES (1, N'For Those About To Rock (We Salute You)', 1, 1, 1, N'Angus Young, Malcolm Young, Brian Johnson', 343719, 11170334, 0.99);
INSERT INTO `Track` (`TrackId`, `Name`, `AlbumId`, `MediaTypeId`, `GenreId`, `Milliseconds`, `Bytes`, `UnitPrice`) VALUES (2, N'Balls to the Wall', 2, 2, 1, 342562, 5510424, 0.99);
INSERT INTO `Track` (`TrackId`, `Name`, `AlbumId`, `MediaTypeId`, `GenreId`, `Composer`, `Milliseconds`, `Bytes`, `UnitPrice`) VALUES (3, N'Fast As a Shark', 3, 2, 1, N'F. Baltes, S. Kaufman, U. Dirkscneider & W. Hoffman', 230619, 3990994, 0.99);
INSERT INTO `Track` (`TrackId`, `Name`, `AlbumId`, `MediaTypeId`, `GenreId`, `Composer`, `Milliseconds`, `Bytes`, `UnitPrice`) VALUES (4, N'Restless and Wild', 3, 2, 1, N'F. Baltes, R.A. Smith-Diesel, S. Kaufman, U. Dirkscneider & W. Hoffman', 252051, 4331779, 0.99);
INSERT INTO `Track` (`TrackId`, `Name`, `AlbumId`, `MediaTypeId`, `GenreId`, `Composer`, `Milliseconds`, `Bytes`, `UnitPrice`) VALUES (5, N'Princess of the Dawn', 3, 2, 1, N'Deaffy & R.A. Smith-Diesel', 375418, 6290521, 0.99);
INSERT INTO `Track` (`TrackId`, `Name`, `AlbumId`, `MediaTypeId`, `GenreId`, `Composer`, `Milliseconds`, `Bytes`, `UnitPrice`) VALUES (6, N'Put The Finger On You', 1, 1, 1, N'Angus Young, Malcolm Young, Brian Johnson', 205662, 6713451, 0.99);
INSERT INTO `Track` (`TrackId`, `Name`, `AlbumId`, `MediaTypeId`, `GenreId`, `Composer`, `Milliseconds`, `Bytes`, `UnitPrice`) VALUES (7, N'Let''s Get It Up', 1, 1, 1, N'Angus Young, Malcolm Young, Brian Johnson', 233926, 7636561, 0.99);
.
.
媒体类型表:
INSERT INTO `MediaType` (`MediaTypeId`, `Name`) VALUES (1, N'MPEG audio file');
INSERT INTO `MediaType` (`MediaTypeId`, `Name`) VALUES (2, N'Protected AAC audio file');
INSERT INTO `MediaType` (`MediaTypeId`, `Name`) VALUES (3, N'Protected MPEG-4 video file');
INSERT INTO `MediaType` (`MediaTypeId`, `Name`) VALUES (4, N'Purchased AAC audio file');
INSERT INTO `MediaType` (`MediaTypeId`, `Name`) VALUES (5, N'AAC audio file');
我的 mysql 目前无法显示 ER 图,但我可以用油漆绘制
我知道我的问题与 join 子句有关,但我可以弄清楚如何执行此查询。