FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SQL-with-Problem-Solving/SelectQueryI.sql at main · Ak-Rajak/SQL-with-Problem-Solving · GitHub
Ak-Rajak
/
SQL-with-Problem-Solving
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SQL-with-Problem-Solving
/
SelectQueryI.sql
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (43 loc) · 1.52 KB
Breadcrumbs
SQL-with-Problem-Solving
/
SelectQueryI.sql
Copy path
File metadata and controls
50 lines (43 loc) · 1.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
--
Question link - https://www.hackerrank.com/challenges/revising-the-select-query/problem?isFullScreen=true
--
Language: T-SQL
--
Database: MySQL/PostgreSQL/SQL Server compatible
/*
Problem: Revising the Select Query I
Query all columns for all American cities in the CITY table with populations larger than 100000.
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
*
FROM
city
WHERE
(
population
>
100000
)
AND
countryCode
=
'
USA'
;
/*
Explanation:
- SELECT * retrieves all columns from the table (ID, NAME, COUNTRYCODE, DISTRICT, POPULATION)
- FROM city: Specifies the CITY table as the data source
- WHERE clause filters rows based on two conditions:
1. population > 100000 (cities with more than 100,000 people)
2. countryCode='USA' (only American cities)
- AND operator ensures both conditions must be satisfied simultaneously
Expected Output:
Returns all columns for American cities with population exceeding 100,000.
Each row will contain: ID, NAME, COUNTRYCODE, DISTRICT, POPULATION
Performance Notes:
- This query performs a table scan with conditional filtering
- Consider indexing on COUNTRYCODE and POPULATION for better performance
- The query is compatible with standard SQL databases
*/
Back
|
FazBrowse Home
|
New Git URL