-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAverages.sql
More file actions
22 lines (17 loc) · 812 Bytes
/
Averages.sql
File metadata and controls
22 lines (17 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
Averages
=================================
Query the average population of all cities in CITY where District is California.
*/
DECLARE @tbl_CITY AS TABLE (ID int, [Name] varchar(17),CountryCode varchar(3),District varchar(20),[Population] int)
INSERT INTO @tbl_CITY VALUES (1,'CITY1','001','DIS1',100000)
INSERT INTO @tbl_CITY VALUES (2,'CITY2','002','California',200000)
INSERT INTO @tbl_CITY VALUES (3,'CITY3','003','DIS3',300000)
INSERT INTO @tbl_CITY VALUES (4,'CITY4','004','California',400000)
INSERT INTO @tbl_CITY VALUES (5,'CITY5','005','DIS5',500000)
SELECT AVG([Population]) AS TotalPopulation FROM @tbl_CITY WHERE District='California';
/*
Hacker Rank Submission
----------------------
SELECT AVG([Population]) AS TotalPopulation FROM CITY WHERE District='California';
*/