-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackos_SQL_code.sql
More file actions
60 lines (43 loc) · 2.02 KB
/
Copy pathHackos_SQL_code.sql
File metadata and controls
60 lines (43 loc) · 2.02 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
53
54
55
56
57
58
59
-- query for getting all column for all american cities.. with population larger than 100000
-- and here country code for america is 'USA'
SELECT * FROM CITY
WHERE POPULATION > 100000 and COUNTRYCODE = 'USA';
-- all american cities with population larger than 120000 and with american country code 'USA'
SELECT NAME FROM CITY
WHERE POPULATION > 120000 and COUNTRYCODE = 'USA';
-- all column for every row in CITY table
SELECT * FROM CITY;
-- all column for every row in CITY table where ID is 1661
SELECT * FROM CITY
WHERE ID = 1661;
-- all column for every japanese CITY table where country code is JPN
SELECT * FROM CITY
WHERE COUNTRYCODE = 'JPN';
-- names of all the japanese CITY table where country code is JPN
SELECT NAME FROM CITY
WHERE COUNTRYCODE = 'JPN';
-- List CIty and state from station table
SELECT CITY,STATE FROM STATION;
-- list of Distinct city names from STATION table where ID is Even
SELECT DISTINCT CITY FROM STATION
WHERE MOD(ID,2) = 0;
/*
Enter your query here and follow these instructions:
1. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error.
2. The AS keyword causes errors, so follow this convention: "Select t.Field From table1 t" instead of "select t.Field From table1 AS t"
3. Type your code immediately after comment. Don't leave any blank line.
*/
-- find difference between total no. of cities and no. distinct City
SELECT COUNT(CITY) - COUNT(DISTINCT(CITY))
FROM STATION ;
/*
Enter your query here and follow these instructions:
1. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error.
2. The AS keyword causes errors, so follow this convention: "Select t.Field From table1 t" instead of "select t.Field From table1 AS t"
3. Type your code immediately after comment. Don't leave any blank line.
*/
-- shortest and longest CITY name
-- SELECT CITY ,Max( LENGTH(CITY)) FROM STATION
-- ORDER BY CITY ASC;
-- SELECT CITY, MIN(LENGTH(CITY)) FROM STATION
-- ORDER BY CITY ASC;