--------------
drop table if exists Student
--------------
--------------
drop table if exists Apply
--------------
--------------
drop table if exists College
--------------
--------------
create table Student (
sID int,
sName text,
GPA float,
sizeHS int)
--------------
--------------
create table Apply (
sID int,
cName text,
major text,
decision boolean)
--------------
--------------
create table College (
cName text,
state char(2),
enrollment int)
--------------
--------------
insert into Student values (123, 'Amy', 3.9, 1000)
--------------
--------------
insert into Student values (234, 'Bob', 3.6, 1500)
--------------
--------------
insert into Student values (320, 'Lori', null, 2500)
--------------
--------------
insert into Student values (345, 'Craig', 3.5, 500)
--------------
--------------
insert into Student values (432, 'Kevin', null, 1500)
--------------
--------------
insert into Student values (456, 'Doris', 3.9, 1000)
--------------
--------------
insert into Student values (543, 'Craig', 3.4, 2000)
--------------
--------------
insert into Student values (567, 'Edward', 2.9, 2000)
--------------
--------------
insert into Student values (654, 'Amy', 3.9, 1000)
--------------
--------------
insert into Student values (678, 'Fay', 3.8, 200)
--------------
--------------
insert into Student values (765, 'Jay', 2.9, 1500)
--------------
--------------
insert into Student values (789, 'Gary', 3.4, 800)
--------------
--------------
insert into Student values (876, 'Irene', 3.9, 400)
--------------
--------------
insert into Student values (987, 'Helen', 3.7, 800)
--------------
--------------
insert into Apply values (123, 'Berkeley', 'CS', true)
--------------
--------------
insert into Apply values (123, 'Cornell', 'EE', true)
--------------
--------------
insert into Apply values (123, 'Stanford', 'CS', true)
--------------
--------------
insert into Apply values (123, 'Stanford', 'EE', false)
--------------
--------------
insert into Apply values (234, 'Berkeley', 'biology', false)
--------------
--------------
insert into Apply values (321, 'MIT', 'history', false)
--------------
--------------
insert into Apply values (321, 'MIT', 'psychology', true)
--------------
--------------
insert into Apply values (345, 'Cornell', 'bioengineering', false)
--------------
--------------
insert into Apply values (345, 'Cornell', 'CS', true)
--------------
--------------
insert into Apply values (345, 'Cornell', 'EE', false)
--------------
--------------
insert into Apply values (345, 'MIT', 'bioengineering', true)
--------------
--------------
insert into Apply values (543, 'MIT', 'CS', false)
--------------
--------------
insert into Apply values (678, 'Stanford', 'history', true)
--------------
--------------
insert into Apply values (765, 'Cornell', 'history', false)
--------------
--------------
insert into Apply values (765, 'Cornell', 'psychology', true)
--------------
--------------
insert into Apply values (765, 'Stanford', 'history', true)
--------------
--------------
insert into Apply values (876, 'MIT', 'biology', true)
--------------
--------------
insert into Apply values (876, 'MIT', 'marine biology', false)
--------------
--------------
insert into Apply values (876, 'Stanford', 'CS', false)
--------------
--------------
insert into Apply values (987, 'Berkeley', 'CS', true)
--------------
--------------
insert into Apply values (987, 'Stanford', 'CS', true)
--------------
--------------
insert into College values ('Berkeley', 'CA', 36000)
--------------
--------------
insert into College values ('Cornell', 'NY', 21000)
--------------
--------------
insert into College values ('Irene', 'TX', 25000)
--------------
--------------
insert into College values ('MIT', 'MA', 10000)
--------------
--------------
insert into College values ('Stanford', 'CA', 15000)
--------------
--------------
select *
from Student where (GPA > 3.7)
--------------
| sID | sName | GPA | sizeHS |
|---|
| 123 | Amy | 3.9 | 1000 |
| 456 | Doris | 3.9 | 1000 |
| 654 | Amy | 3.9 | 1000 |
| 678 | Fay | 3.8 | 200 |
| 876 | Irene | 3.9 | 400 |
| 987 | Helen | 3.7 | 800 |
--------------
select *
from Student
where (GPA > 3.7) and (sizeHS < 1000)
--------------
| sID | sName | GPA | sizeHS |
|---|
| 678 | Fay | 3.8 | 200 |
| 876 | Irene | 3.9 | 400 |
| 987 | Helen | 3.7 | 800 |
--------------
select *
from Apply
where (cName = 'Stanford') and (major = 'CS')
--------------
| sID | cName | major | decision |
|---|
| 123 | Stanford | CS | 1 |
| 876 | Stanford | CS | 0 |
| 987 | Stanford | CS | 1 |
--------------
select sID, decision
from Apply
--------------
| sID | decision |
|---|
| 123 | 1 |
| 123 | 1 |
| 123 | 1 |
| 123 | 0 |
| 234 | 0 |
| 321 | 0 |
| 321 | 1 |
| 345 | 0 |
| 345 | 1 |
| 345 | 0 |
| 345 | 1 |
| 543 | 0 |
| 678 | 1 |
| 765 | 0 |
| 765 | 1 |
| 765 | 1 |
| 876 | 1 |
| 876 | 0 |
| 876 | 0 |
| 987 | 1 |
| 987 | 1 |
--------------
select sID, sName
from Student
where (GPA > 3.7)
--------------
| sID | sName |
|---|
| 123 | Amy |
| 456 | Doris |
| 654 | Amy |
| 678 | Fay |
| 876 | Irene |
| 987 | Helen |
--------------
select major, decision
from Apply
--------------
| major | decision |
|---|
| CS | 1 |
| EE | 1 |
| CS | 1 |
| EE | 0 |
| biology | 0 |
| history | 0 |
| psychology | 1 |
| bioengineering | 0 |
| CS | 1 |
| EE | 0 |
| bioengineering | 1 |
| CS | 0 |
| history | 1 |
| history | 0 |
| psychology | 1 |
| history | 1 |
| biology | 1 |
| marine biology | 0 |
| CS | 0 |
| CS | 1 |
| CS | 1 |
--------------
select distinct major, decision
from Apply
--------------
| major | decision |
|---|
| CS | 1 |
| EE | 1 |
| EE | 0 |
| biology | 0 |
| history | 0 |
| psychology | 1 |
| bioengineering | 0 |
| bioengineering | 1 |
| CS | 0 |
| history | 1 |
| biology | 1 |
| marine biology | 0 |
--------------
drop table if exists Student
--------------
--------------
drop table if exists Apply
--------------
--------------
drop table if exists College
--------------