-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathITOracle12-3781.sql
More file actions
76 lines (60 loc) · 1.95 KB
/
ITOracle12-3781.sql
File metadata and controls
76 lines (60 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
--1st Run the following
DROP TABLE Subs;
DROP Table ships;
CREATE TABLE Subs
(SUB_ID varchar2(5),
CAPTAIN varchar2(25))
;
INSERT ALL
INTO Subs (SUB_ID, CAPTAIN) VALUES ('I-166', 'Suwa Koichiro')
INTO Subs (SUB_ID, CAPTAIN) VALUES ('I-176', 'Okada Hideo')
INTO Subs (SUB_ID, CAPTAIN) VALUES ('I-177', 'Matsumura Kanji')
INTO Subs (SUB_ID, CAPTAIN) VALUES ('I-180', 'Fujita Hidenori')
INTO Subs (SUB_ID, CAPTAIN) VALUES ('I-182', 'Yonehara Minoru')
SELECT * FROM dual
;
CREATE TABLE ships
(Ship varchar2(13),
Country varchar2(2),
SUB_ID varchar2(5))
;
INSERT ALL
INTO ships (Ship, Country, SUB_ID) VALUES ('SS Fingal', 'NL', 'I-180')
INTO ships (Ship, Country, SUB_ID) VALUES ('AHS Centaur', 'AU', 'I-177')
INTO ships (Ship, Country, SUB_ID) VALUES ('HNLMS K XVI', 'NL', 'I-166')
INTO ships (Ship, Country, SUB_ID) VALUES ('USAT Liberty', 'US', 'I-166')
INTO ships (Ship, Country, SUB_ID) VALUES ('USS Seadragon', 'US', NULL)
SELECT * FROM dual
;
-- 2nd Look at the tables
-- Here are the tables
SET ECHO ON;
SELECT * FROM ships;
SELECT * FROM subs;
-- 3rd answer the following
-- send me both the code and the results via email.
-- Questions for today's in-class (all of these can be done without a join)
--1. Find all the ship names in the SHIPS table
SET ECHO ON;
SELECT * FROM ships;
--2. Find the number of ships in the SHIPS table
SET ECHO ON;
SELECT COUNT(*) FROM ships;
--3. Find the ship names and the number of the sub that sank them
SET ECHO ON;
SELECT Ship, SUB_ID FROM ships;
--4. Find the number of ships sank by sub I-166
SET ECHO ON;
SELECT COUNT(*)
FROM ships
WHERE SUB_ID='I-166';
--5. Find the ship names and the number of the sub that sank them -- ONLY for US ships
SET ECHO ON;
SELECT Ship, SUB_ID
FROM ships
WHERE Country='US';
--6. Find the number of US ships NOT attacked/sank in the SHIPS table
SET ECHO ON;
SELECT COUNT(*)
FROM ships
WHERE Country='US' AND SUB_ID IS null;