-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a103ce6
Showing
45 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SELECT N, | ||
( | ||
CASE | ||
WHEN P IS NULL THEN "Root" | ||
WHEN N NOT IN (SELECT P FROM BST WHERE P IS NOT NULL) THEN "Leaf" | ||
ELSE "Inner" | ||
END | ||
) | ||
FROM BST | ||
ORDER BY N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
1. Query an alphabetically ordered list of all names in OCCUPATIONS, immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example: AnActorName(A), ADoctorName(D), AProfessorName(P), and ASingerName(S). | ||
Example: | ||
Ashely(P) | ||
Christeen(P) | ||
Jane(A) | ||
Jenny(D) | ||
*/ | ||
SELECT CONCAT(Name,'(',CASE | ||
WHEN Occupation = 'Actor' THEN 'A' | ||
WHEN Occupation = 'Doctor' THEN 'D' | ||
WHEN Occupation = 'Singer' THEN 'S' | ||
WHEN Occupation = 'Professor' THEN 'P' | ||
END,')') FROM OCCUPATIONS | ||
ORDER BY Name; | ||
|
||
/* | ||
2.Query the number of ocurrences of each occupation in OCCUPATIONS. Sort the occurrences in ascending order, and output them in the following format: | ||
There are a total of [occupation_count] [occupation]s. | ||
where [occupation_count] is the number of occurrences of an occupation in OCCUPATIONS and [occupation] is the lowercase occupation name. If more than one Occupation has the same [occupation_count], they should be ordered alphabetically. | ||
*/ | ||
|
||
SELECT CONCAT('There are a total of ',COUNT(occupation),' ',LOWER(occupation),'s.') | ||
FROM OCCUPATIONS | ||
GROUP BY occupation | ||
ORDER BY COUNT(occupation) ASC, occupation ASC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SELECT CASE | ||
WHEN A + B > C AND B + C > A AND A + C > B THEN | ||
CASE | ||
WHEN A = B AND B = C THEN 'Equilateral' | ||
WHEN A = B OR B = C OR A = C THEN 'Isosceles' | ||
ELSE 'Scalene' | ||
END | ||
ELSE 'Not A Triangle' | ||
END | ||
FROM TRIANGLES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT ROUND(AVG(POPULATION)) FROM CITY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT SUM(POPULATION) FROM CITY | ||
WHERE COUNTRYCODE = 'JPN' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT (SELECT MAX(POPULATION) FROM CITY) - (SELECT MIN(POPULATION) FROM CITY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT AVG(POPULATION) FROM CITY | ||
WHERE DISTRICT = 'California' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT COUNT(ID) FROM CITY | ||
WHERE POPULATION > 100000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT SUM(POPULATION) FROM CITY | ||
WHERE DISTRICT = 'California' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT (SELECT ROUND(AVG(Salary)) FROM EMPLOYEES) - (SELECT ROUND(AVG(REPLACE(Salary, '0', ''))) FROM EMPLOYEES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT MAX(months*salary), COUNT(salary) FROM EMPLOYEE | ||
WHERE months * salary = (SELECT MAX(months*salary) FROM EMPLOYEE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT TRUNCATE(SUM(LAT_N),4) FROM STATION | ||
WHERE LAT_N > 38.7880 AND LAT_N < 137.2345 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT TRUNCATE(MAX(LAT_N),4) FROM STATION | ||
WHERE LAT_N < 137.2345 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT ROUND(LONG_W,4) FROM STATION | ||
WHERE LAT_N = (SELECT MAX(LAT_N) FROM STATION | ||
WHERE LAT_N < 137.2345) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT ROUND(MIN(LAT_N),4) FROM STATION | ||
WHERE LAT_N > 38.7780 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SELECT ROUND(LONG_W,4) FROM STATION | ||
WHERE LAT_N > 38.7780 | ||
ORDER BY LAT_N | ||
LIMIT 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* | ||
p1(x1, y1) and p2(x2, y2) | ||
|x1 - x2| + |y1 - y2| | ||
*/ | ||
SELECT ROUND(ABS(MIN(LAT_N) - MAX(LAT_N)) + ABS(MIN(LONG_W) - MAX(LONG_W)),4) FROM STATION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
p1(min lat, min long) p2(max lat, max long) | ||
*/ | ||
SELECT ROUND( | ||
SQRT( | ||
POW(MAX(LAT_N) - MIN(LAT_N),2)+ | ||
POW(MAX(LONG_W) - MIN(LONG_W),2) | ||
) | ||
,4) FROM STATION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* | ||
ROUND(sayi, 2) | ||
*/ | ||
SELECT ROUND(SUM(LAT_N),2), ROUND(SUM(LONG_W),2) | ||
FROM STATION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- indexes | ||
SET @lower = CEILING((SELECT COUNT(LAT_N) FROM STATION)/2); | ||
SET @upper = FLOOR(((SELECT COUNT(LAT_N) FROM STATION)/2)+1); | ||
|
||
SET @one = 1; | ||
SET @lower = @lower - 1; | ||
|
||
PREPARE stmt FROM 'SELECT @i := ROUND(LAT_N,4) FROM STATION ORDER BY LAT_N DESC LIMIT ?,?'; | ||
EXECUTE stmt USING @lower, @one; | ||
|
||
-- NOT COMPLETED! DATASET COUNT IS ODD SO TEST PASSES. BUT I NEED TO TAKE AVERAGE OF TWO NUMBER FOR EVEN DATASET COUNT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Enter your query here. | ||
Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. | ||
*/ | ||
DECLARE @i INTEGER; | ||
SET @i = 20; | ||
|
||
WHILE @i > 0 | ||
BEGIN | ||
SELECT REPLICATE('* ', @i); | ||
SET @i = @i - 1; | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Enter your query here. | ||
Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. | ||
*/ | ||
DECLARE @i INTEGER; | ||
SET @i = 1; | ||
|
||
WHILE @i <= 20 | ||
BEGIN | ||
SELECT REPLICATE('* ', @i); | ||
SET @i = @i + 1; | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
query the names of all cities where the CONTINENT is 'Africa'. | ||
*/ | ||
SELECT NAME FROM CITY | ||
WHERE COUNTRYCODE IN (SELECT CODE FROM COUNTRY | ||
WHERE CONTINENT = 'Africa') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
Given the CITY and COUNTRY tables, query the sum of the populations of all cities where the CONTINENT is 'Asia'. | ||
*/ | ||
SELECT SUM(POPULATION) FROM CITY | ||
WHERE COUNTRYCODE IN (SELECT CODE FROM COUNTRY | ||
WHERE CONTINENT = 'Asia') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer. | ||
*/ | ||
SELECT CONTINENT, FLOOR(AVG(CITY.POPULATION)) | ||
FROM COUNTRY | ||
INNER JOIN CITY ON CITY.COUNTRYCODE = COUNTRY.CODE | ||
GROUP BY CONTINENT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT Name FROM Employee | ||
ORDER BY Name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT name FROM Employee | ||
WHERE salary > 2000 AND months < 10 | ||
ORDER BY employee_id ASC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT Name FROM STUDENTS | ||
WHERE Marks > 75 | ||
ORDER BY RIGHT(Name,3), ID ASC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT * FROM CITY | ||
WHERE COUNTRYCODE = 'JPN' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT NAME FROM CITY | ||
WHERE COUNTRYCODE = 'JPN' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT * FROM CITY | ||
WHERE COUNTRYCODE = 'USA' AND POPULATION > 100000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT NAME FROM CITY | ||
WHERE COUNTRYCODE = 'USA' AND POPULATION > 120000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT * FROM CITY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT * FROM CITY | ||
WHERE ID=1661 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT CITY, STATE FROM STATION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT DISTINCT CITY FROM STATION | ||
WHERE CITY REGEXP '[^aeiou]$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT DISTINCT CITY FROM STATION | ||
WHERE CITY REGEXP '^[^aeiou]' OR CITY REGEXP '[^aeiou]$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT DISTINCT CITY FROM STATION | ||
WHERE CITY REGEXP '^[^aeiou].*[^aeiou]$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT DISTINCT CITY FROM STATION | ||
WHERE ID%2=0 | ||
ORDER BY CITY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT (SELECT COUNT(CITY) FROM STATION) - (SELECT COUNT(DISTINCT CITY) FROM STATION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) ASC, CITY LIMIT 1; | ||
SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) DESC, CITY LIMIT 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[aeiou]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '[aeiou]$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[aeiou].*[aeiou]$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SELECT DISTINCT CITY FROM STATION | ||
WHERE CITY REGEXP '^[^aeiou]' |