我有这些表和值:查询,而无需使用除了
create table Instrument (
instrumentnaam varchar(14) not null,
toonhoogte varchar(7) not null
)
INSERT INTO instrument VALUES ('piano', '' );
INSERT INTO instrument VALUES ('fluit', '' );
INSERT INTO instrument VALUES ('fluit', 'alt' );
INSERT INTO instrument VALUES ('saxofoon', 'alt' );
INSERT INTO instrument VALUES ('saxofoon', 'tenor' );
INSERT INTO instrument VALUES ('saxofoon', 'sopraan');
INSERT INTO instrument VALUES ('gitaar', '' );
INSERT INTO instrument VALUES ('viool', '' );
INSERT INTO instrument VALUES ('viool', 'alt' );
INSERT INTO instrument VALUES ('drums', '' );
create table Bezettingsregel (
stuknr numeric(5) not null,
instrumentnaam varchar(14) not null,
toonhoogte varchar(7) not null,
aantal numeric(2) not null
)
INSERT INTO bezettingsregel VALUES (2, 'drums', '', 1);
INSERT INTO bezettingsregel VALUES (2, 'saxofoon', 'alt', 2);
INSERT INTO bezettingsregel VALUES (2, 'saxofoon', 'tenor', 1);
INSERT INTO bezettingsregel VALUES (2, 'piano', '', 1);
INSERT INTO bezettingsregel VALUES (3, 'fluit', '', 1);
INSERT INTO bezettingsregel VALUES (5, 'fluit', '', 3);
INSERT INTO bezettingsregel VALUES (9, 'fluit', '', 1);
INSERT INTO bezettingsregel VALUES (9, 'fluit', 'alt', 1);
INSERT INTO bezettingsregel VALUES (9, 'piano', '', 1);
INSERT INTO bezettingsregel VALUES (12, 'piano', '', 1);
INSERT INTO bezettingsregel VALUES (12, 'fluit', '', 2);
INSERT INTO bezettingsregel VALUES (13, 'drums', '', 1);
INSERT INTO bezettingsregel VALUES (13, 'saxofoon', 'alt', 1);
INSERT INTO bezettingsregel VALUES (13, 'saxofoon', 'tenor', 1);
INSERT INTO bezettingsregel VALUES (13, 'fluit', '', 2);
INSERT INTO bezettingsregel VALUES (14, 'piano', '', 1);
INSERT INTO bezettingsregel VALUES (14, 'fluit', '', 1);
INSERT INTO bezettingsregel VALUES (15, 'saxofoon', 'alt', 2);
INSERT INTO bezettingsregel VALUES (15, 'fluit', 'alt', 2);
INSERT INTO bezettingsregel VALUES (15, 'piano', '', 1);
create table Stuk (
stuknr numeric(5) not null,
componistId numeric(4) not null,
titel varchar(20) not null,
stuknrOrigineel numeric(5) null,
genrenaam varchar(10) not null,
niveaucode char(1) null,
speelduur numeric(3,1) null,
jaartal numeric(4) not null
)
INSERT INTO stuk VALUES (1, 1, 'Blue bird', NULL, 'jazz', NULL, 4.5, 1954);
INSERT INTO stuk VALUES (2, 2, 'Blue bird', 1, 'jazz', 'B', 4, 1988);
INSERT INTO stuk VALUES (3, 4, 'Air pur charmer', NULL, 'klassiek', 'B', 4.5, 1953);
INSERT INTO stuk VALUES (5, 5, 'Lina', NULL, 'klassiek', 'B', 5, 1979);
INSERT INTO stuk VALUES (8, 8, 'Berceuse', NULL, 'klassiek', NULL, 4, 1786);
INSERT INTO stuk VALUES (9, 2, 'Cradle song', 8, 'klassiek', 'B', 3.5, 1990);
INSERT INTO stuk VALUES (10, 8, 'Non piu andrai', NULL, 'klassiek', NULL, NULL, 1791);
INSERT INTO stuk VALUES (12, 9, 'I''ll never go', 10, 'pop', 'A', 6, 1996);
INSERT INTO stuk VALUES (13, 10, 'Swinging Lina', 5, 'jazz', 'B', 8, 1997);
INSERT INTO stuk VALUES (14, 5, 'Little Lina', 5, 'klassiek', 'A', 4.3, 1998);
INSERT INTO stuk VALUES (15, 10, 'Blue sky', 1, 'jazz', 'A', 4, 1998);
现在我想编写一个查询,显示的是正在使用中的流派“klassiek”但不是在体裁“爵士”的仪器。我需要做到这一点,而无需使用EXCEPT
这是我的尝试:
SELECT i.instrumentnaam
FROM instrument i inner join
bezettingsregel b on i.instrumentnaam = b.instrumentnaam
inner join stuk s on b.stuknr = s.stuknr
WHERE genrenaam = 'klassiek'
AND NOT EXISTS (SELECT stuknr
FROM stuk
WHERE genrenaam = 'jazz'
)
我无法弄清楚。感谢帮助!
你也许是学生吗?我的笔记本电脑上有完全相同的桌子和东西供学校使用。 – iPhantomGuy
是的,我准备明天 – Yakalent
不错,我也是韩国人。大测试来了吧? – iPhantomGuy