-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07.BJ02-AfricanCities.sql
99 lines (77 loc) · 2.42 KB
/
07.BJ02-AfricanCities.sql
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
African Cities
Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is 'Africa'.
Note: CITY.CountryCode and COUNTRY.Code are matching key column
Input Format
The CITY and COUNTRY tables are described as follows:
CITY
+-------------+--------------+
| Field | Type |
+-------------+--------------+
| ID | number |
| Name | varchar2(17) |
| CountryCode | varchar2(3) |
| District | varchar2(20) |
| Population | number |
+-------------+--------------+
COUNTRY
+----------------+--------------+
| Field | Type |
+----------------+--------------+
| Code | varchar2(3) |
| Name | varchar2(44) |
| Continent | varchar2(13) |
| Region | varchar2(25) |
| SurfaceArea | number |
| IndepYear | varchar2(5) |
| Population | number |
| Lifeexpectancy | varchar2(4) |
| GNP | number |
| GNPOLD | varchar2(9) |
| LocalName | varchar2(44) |
| GovernmentForm | varchar2(44) |
| HeadofState | varchar2(32) |
| Capital | varchar2(4) |
| Code2 | varchar2(2) |
+----------------+--------------+
*/
use hackerrank;
GO
raiserror('Now at basicjoin.proc_02africancities creation ....',0,1)
GO
CREATE or ALTER PROCEDURE basicjoin.proc_02africancities AS
SELECT
c.name
FROM
basicjoin.CITY c,
basicjoin.COUNTRY cc
WHERE
c.countrycode = cc.code and
cc.CONTINENT = 'Africa';
GO
raiserror('Now at BasicJoinTestClass.test_02africancities creation ....',0,1)
GO
CREATE or ALTER PROCEDURE BasicJoinTestClass.test_02africancities
AS
BEGIN
IF OBJECT_ID('actual') IS NOT NULL DROP TABLE actual;
IF OBJECT_ID('expected') IS NOT NULL DROP TABLE expected;
CREATE TABLE actual (
NAME varchar(44) NOT NULL,
);
INSERT INTO actual (NAME) exec basicjoin.proc_02africancities
CREATE TABLE expected (
NAME varchar(44) NOT NULL,
);
INSERT INTO expected (NAME) SELECT 'Qina'
INSERT INTO expected (NAME) SELECT 'Warraq al-Arab'
INSERT INTO expected (NAME) SELECT 'Kempton Park'
INSERT INTO expected (NAME) SELECT 'Alberton'
INSERT INTO expected (NAME) SELECT 'Klerksdorp'
INSERT INTO expected (NAME) SELECT 'Uitenhage'
INSERT INTO expected (NAME) SELECT 'Brakpan'
INSERT INTO expected (NAME) SELECT 'Libreville'
EXEC tSQLt.AssertEqualsTable 'expected', 'actual';
END
GO
--exec tSQLt.Run 'BasicJoinTestClass.[test_02africancities]';