-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.BS02-Query-II.sql
70 lines (50 loc) · 1.53 KB
/
04.BS02-Query-II.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
/*
Revising the Select Query II
Query the names of all American cities in CITY with populations larger than 120000. The CountryCode for America is USA.
Input Format:
The CITY table is described as follows:
+-------------+--------------+
| FILEDS | TYPE |
+-------------+--------------+
| ID | NUMBER |
| NAME | VARCHAR2(17) |
| COUNRTYCODE | VARCHAR2(3) |
| DISTRICT | VARCHAR2(20) |
| POPULATION | NUMBER |
+-------------+--------------+
*/
use hackerrank;
GO
raiserror('Now at the create procedure section ....',0,1)
GO
CREATE or ALTER PROCEDURE basicselect.proc_02query2 AS
select
basicselect.CITY.name as NAME
from
basicselect.CITY
where
basicselect.CITY.POPULATION > 120000 and
basicselect.CITY.COUNTRYCODE = 'USA'
order by basicselect.CITY.id;
GO
CREATE or ALTER PROCEDURE BasicSelectTestClass.test_02query2
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(17),
);
INSERT INTO actual (NAME) exec basicselect.proc_02query2;
CREATE TABLE expected (
NAME varchar(17),
);
INSERT INTO expected (NAME) SELECT 'El Paso'
INSERT INTO expected (NAME) SELECT 'Scottsdale'
INSERT INTO expected (NAME) SELECT 'Corona'
INSERT INTO expected (NAME) SELECT 'Concord'
INSERT INTO expected (NAME) SELECT 'Cedar Rapids'
EXEC tSQLt.AssertEqualsTable 'expected', 'actual';
END;
GO
--exec tSQLt.Run 'BasicSelectTestClass.[test_02query2]';