-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectQueryII.sql
More file actions
52 lines (45 loc) · 1.38 KB
/
SelectQueryII.sql
File metadata and controls
52 lines (45 loc) · 1.38 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
-- Question link - https://www.hackerrank.com/challenges/revising-the-select-query-2/problem?isFullScreen=true
-- Language: T-SQL
-- Database: MySQL/PostgreSQL/SQL Server compatible
/*
Problem: Revising the Select Query II
Query the NAME field for all American cities in the CITY table with populations larger than 120000.
The CountryCode for America is USA.
Table Schema:
CITY
- ID (INTEGER)
- NAME (VARCHAR2)
- COUNTRYCODE (CHAR(3))
- DISTRICT (VARCHAR2)
- POPULATION (INTEGER)
Input Format:
The CITY table is described as follows:
Field | Type
------------|----------
ID | NUMBER
NAME | VARCHAR2(17)
COUNTRYCODE | CHAR(3)
DISTRICT | VARCHAR2(20)
POPULATION | NUMBER
*/
-- Solution:
SELECT name FROM city
WHERE (population > 120000) AND countryCode="USA";
/*
Explanation:
- SELECT name: Only retrieves the NAME column instead of all columns
- FROM city: Specifies the CITY table as the data source
- WHERE clause applies two filtering conditions:
1. population > 120000 (cities with more than 120,000 people)
2. countryCode="USA" (only American cities)
- AND operator ensures both conditions must be satisfied
- Result: Names of large American cities with population exceeding 120,000
Expected Output:
Returns a single column containing city names that meet the criteria.
Sample cities that might be returned:
- New York
- Los Angeles
- Chicago
- Houston
- Phoenix
*/