SQL - SQLite - Python - サブクエリ - クエリの中にあるクエリ - SELECT, 外部クエリ, 内部クエリ
Head First SQL ―頭とからだで覚えるSQLの基本、 Lynn Beighley(著)、 佐藤 直生(監訳)、 松永 多苗子(翻訳)、 オライリージャパンの 9章(サブクエリ - クエリの中にあるクエリ)、p.401(サブクエリ構築ワークショップ)の解答を求めてみる。
schema2.sql
-- 1.
select AVG(jc.salary)
from job_current jc
where jc.title = 'Web開発者';
-- 2.
select mc.first_name, mc.last_name, jc.salary
from my_contacts
natural join job_current jc
where jc.current = 'Web開発者';
-- 3.
select
mc.first_name,
mc.last_name,
jc.salary,
jc.salary - (select AVG(jc.salary)
from job_current jc
where jc.title = 'Web開発者')
from my_contacts
natural join job_current jc
where jc.current = 'Web開発者';