SQLに次のテーブルがあるとします。SQLでチェーンクエリを作成できません
student
name id
alex 1
felix 2
hannah 3
john 4
jonas 5
instructor
name id
alex 1
felix 2
hannah 3
john 4
jonas 5
(ex)brad 8
tom 9
tonny 11
instructor_lectures
name id course_count
alex 1 5
felix 2 2
hannah 3 0
john 4 23
jonas 5 12
(ex)brad 8 1
tom 9 11
tonny 11 9
私がしたいことは、私が意味する
- firstly, get the difference of instructor student tables according to the name which does not start with "(ex)"
- and then list course_count of the result.
、最初
name id
tom 9
tonny 11
、その後
name id course_count
tom 9 11
tonny 11 9
は、私がこれまで何をしているのですか?
私はinstructor_lecturesから差分クエリと選択クエリを作成しましたが、それらを組み合わせることはできませんでした。
SELECT NAME FROM instructor INSTR WHERE NOT EXISTS
(
SELECT * FROM student STU WHER INSTR.NAME = STU.NAME
)
AND INSTR.NAME NOT REGEXP '^(ex)'
このクエリは、私を返し
name id
tom 9
tonny 11
は今、私は
SELECT NAME FROM instructor INSTR WHERE NOT EXISTS
(
SELECT * FROM student STU WHER INSTR.NAME = STU.NAME
)
AND INSTR.NAME NOT REGEXP '^(ex)'
SELECT * FROM instructor_lectures INSTR_LECTURES WHERE INSTR.NAME = INSTR_LECTURES.NAME
instructor_lectures表を見ることでcourse_countを取得したいが、これはエラーをスローします。私のミスはどこですか?最初の差分クエリの結果のcourse_countを取得するにはどうすればよいですか?
上の情報のため、結合条件を使用できますか? –