私はこれらの3つのテーブル持っている:SQL Serverのクエリが作曲の曲で最も学校を取得
create table musicSchool
(
schoolId numeric(2) not null,
name varchar(30) not null,
city varchar(20) not null
)
create table Composer
(
composerId numeric(4) not null,
name varchar(20) not null,
birthday datetime null,
schoolId numeric(2) null
)
create table Song
(
songnumber numeric(5) not null,
composerId numeric(4) not null,
title varchar(20) not null,
year numeric(4) not null
)
は今、私はほとんどの作曲家の曲で、学校や学校にしたいです。
SELECT
M.name, COUNT(M.name)
FROM
musicSchool M
INNER JOIN
Composer C ON M.schoolId = C.schoolId
INNER JOIN
Song S ON C.composerId= S.composerId
GROUP BY
M.name
私は作曲家の曲の彼らの合計数と学校を取得するが、私は作曲の曲の数が最も多い学校/学校にしたいです。
ありがとうございました!
これは基本的な参加演習です。ここには存在と副問合せは必要ありません。内部結合と基本的な集約。ヒント、COUNTを見てください。 –
テーブルComposerと曲の間で結合を適用し、それからmusicSchoolテーブルのanyでチェックしてください –
一見すると、これは「関係分割」の問題のようです。 SQL Server Relational DivisionのGoogle検索を実行してください... https://www.google.com/search?q=sql+server+relational+division&rlz=1C1ASUC_enUS560US561&oq=sql+server+relational+division&aqs=chrome..69i57.7575j0j7&sourceid = chrome&ie = UTF-8 –