Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
teyyihan committed Nov 22, 2020
0 parents commit a103ce6
Show file tree
Hide file tree
Showing 45 changed files with 184 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Advanced Select/Binary Tree Nodes.sql
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
28 changes: 28 additions & 0 deletions Advanced Select/The PADS.sql
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
10 changes: 10 additions & 0 deletions Advanced Select/Type of Triangle.sql
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;
1 change: 1 addition & 0 deletions Aggregation/Average Population.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT ROUND(AVG(POPULATION)) FROM CITY
2 changes: 2 additions & 0 deletions Aggregation/Japan Population.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT SUM(POPULATION) FROM CITY
WHERE COUNTRYCODE = 'JPN'
1 change: 1 addition & 0 deletions Aggregation/Population Density Difference.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT (SELECT MAX(POPULATION) FROM CITY) - (SELECT MIN(POPULATION) FROM CITY)
2 changes: 2 additions & 0 deletions Aggregation/Revising Aggregations - Averages.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT AVG(POPULATION) FROM CITY
WHERE DISTRICT = 'California'
2 changes: 2 additions & 0 deletions Aggregation/Revising Aggregations - The Count Function.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT COUNT(ID) FROM CITY
WHERE POPULATION > 100000
2 changes: 2 additions & 0 deletions Aggregation/Revising Aggregations - The Sum Function.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT SUM(POPULATION) FROM CITY
WHERE DISTRICT = 'California'
1 change: 1 addition & 0 deletions Aggregation/The Blunder.sql
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)
2 changes: 2 additions & 0 deletions Aggregation/Top Earners.sql
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)
2 changes: 2 additions & 0 deletions Aggregation/Weather Observation Station 13.sql
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
2 changes: 2 additions & 0 deletions Aggregation/Weather Observation Station 14.sql
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
3 changes: 3 additions & 0 deletions Aggregation/Weather Observation Station 15.sql
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)
2 changes: 2 additions & 0 deletions Aggregation/Weather Observation Station 16.sql
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
4 changes: 4 additions & 0 deletions Aggregation/Weather Observation Station 17.sql
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
5 changes: 5 additions & 0 deletions Aggregation/Weather Observation Station 18.sql
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
9 changes: 9 additions & 0 deletions Aggregation/Weather Observation Station 19.sql
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
5 changes: 5 additions & 0 deletions Aggregation/Weather Observation Station 2.sql
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
11 changes: 11 additions & 0 deletions Aggregation/Weather Observation Station 20.sql
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
12 changes: 12 additions & 0 deletions Alternative Queries/Draw The Triangle 1.sql
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;
12 changes: 12 additions & 0 deletions Alternative Queries/Draw The Triangle 2.sql
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;
6 changes: 6 additions & 0 deletions Basic Join/African Cities.sql
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')
6 changes: 6 additions & 0 deletions Basic Join/Asian Population.sql
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')
7 changes: 7 additions & 0 deletions Basic Join/Average Population of Each Continent.sql
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
2 changes: 2 additions & 0 deletions Basic Select/Employee Names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT Name FROM Employee
ORDER BY Name
3 changes: 3 additions & 0 deletions Basic Select/Employee Salaries.sql
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
3 changes: 3 additions & 0 deletions Basic Select/Higher Than 75 Marks.sql
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
2 changes: 2 additions & 0 deletions Basic Select/Japanese Cities' Attributes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT * FROM CITY
WHERE COUNTRYCODE = 'JPN'
2 changes: 2 additions & 0 deletions Basic Select/Japanese Cities' Names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT NAME FROM CITY
WHERE COUNTRYCODE = 'JPN'
2 changes: 2 additions & 0 deletions Basic Select/Revising the Select Query I.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT * FROM CITY
WHERE COUNTRYCODE = 'USA' AND POPULATION > 100000
2 changes: 2 additions & 0 deletions Basic Select/Revising the Select Query II.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT NAME FROM CITY
WHERE COUNTRYCODE = 'USA' AND POPULATION > 120000
1 change: 1 addition & 0 deletions Basic Select/Select All.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM CITY
2 changes: 2 additions & 0 deletions Basic Select/Select By ID.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT * FROM CITY
WHERE ID=1661
1 change: 1 addition & 0 deletions Basic Select/Weather Observation Station 1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT CITY, STATE FROM STATION
2 changes: 2 additions & 0 deletions Basic Select/Weather Observation Station 10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT DISTINCT CITY FROM STATION
WHERE CITY REGEXP '[^aeiou]$'
2 changes: 2 additions & 0 deletions Basic Select/Weather Observation Station 11.sql
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]$'
2 changes: 2 additions & 0 deletions Basic Select/Weather Observation Station 12.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT DISTINCT CITY FROM STATION
WHERE CITY REGEXP '^[^aeiou].*[^aeiou]$'
3 changes: 3 additions & 0 deletions Basic Select/Weather Observation Station 3.sql
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
1 change: 1 addition & 0 deletions Basic Select/Weather Observation Station 4.sql
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)
2 changes: 2 additions & 0 deletions Basic Select/Weather Observation Station 5.sql
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;
1 change: 1 addition & 0 deletions Basic Select/Weather Observation Station 6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[aeiou]'
1 change: 1 addition & 0 deletions Basic Select/Weather Observation Station 7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '[aeiou]$'
1 change: 1 addition & 0 deletions Basic Select/Weather Observation Station 8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[aeiou].*[aeiou]$'
2 changes: 2 additions & 0 deletions Basic Select/Weather Observation Station 9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT DISTINCT CITY FROM STATION
WHERE CITY REGEXP '^[^aeiou]'

0 comments on commit a103ce6

Please sign in to comment.