Last active
August 29, 2015 14:03
-
-
Save tyage/31afada7b1625b749466 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table 学生 (学生番号, 学生名, 都市, 年齢); | |
insert into 学生 values | |
('S1', '山田', '京都', 19), | |
('S2', '鈴木', '大阪', 20), | |
('S3', '小島', '奈良', 22), | |
('S4', '武田', '京都', 18), | |
('S5', '高木', '神戸', 21); | |
create table 科目 (科目番号, 科目名, 先生, 単位数); | |
insert into 科目 values | |
('J1', 'データベース', '田中', 4), | |
('J2', '計算理論', '佐藤', 2), | |
('J3', 'ハードウェア', '小林', 6), | |
('J4', 'データベース', '大野', 4), | |
('J5', 'OS', '斉藤', 5), | |
('J6', '人工知能', '田中', 3); | |
create table 成績 ('学生番号', '科目番号', '点数'); | |
insert into 成績 values | |
('S1', 'J1', 75), | |
('S1', 'J2', 60), | |
('S2', 'J2', 50), | |
('S3', 'J3', 90), | |
('S3', 'J4', 70), | |
('S3', 'J6', 65), | |
('S4', 'J1', 50), | |
('S4', 'J2', 80), | |
('S4', 'J4', 55), | |
('S4', 'J5', 75), | |
('S4', 'J6', 80); | |
-- 問題a | |
select 学生名 from 学生 where 年齢 = 19 and 都市 = '京都'; | |
/* | |
山田 | |
*/ | |
-- 問題b | |
select 学生.学生番号, 成績.点数 from 科目 | |
left join 成績 on 科目.科目番号 = 成績.科目番号 | |
left join 学生 on 学生.学生番号 = 成績.学生番号 | |
where 科目名 = '人工知能'; | |
/* | |
S3|65 | |
S4|80 | |
*/ | |
-- 問題c | |
select 科目.先生 from 学生 | |
left join 成績 on 成績.学生番号 = 学生.学生番号 | |
left join 科目 on 科目.科目番号 = 成績.科目番号 | |
where 年齢 >= 20; | |
/* | |
佐藤 | |
小林 | |
大野 | |
田中 | |
*/ | |
-- 問題d | |
select 学生.学生名 from 科目 | |
left join 成績 on 成績.科目番号 = 科目.科目番号 | |
left join 学生 on 学生.学生番号 = 成績.学生番号 | |
where 先生 = '田中' | |
group by 学生.学生番号; | |
/* | |
山田 | |
小島 | |
武田 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment