Skip to content

Instantly share code, notes, and snippets.

View bartubozkurt's full-sized avatar
🎯
Focusing

Bartu Bozkurt bartubozkurt

🎯
Focusing
View GitHub Profile
@bartubozkurt
bartubozkurt / operators.sql
Created June 11, 2021 17:50
Fetch names of cities that have a population between 500K and 5M
SELECT name
FROM city
WHERE population BETWEEN 500000 AND 5000000;
@bartubozkurt
bartubozkurt / operators_2.sql
Created June 11, 2021 17:52
Fetch names of cities that don't miss a rating value
SELECT name
FROM city
WHERE rating is NOT NULL;
@bartubozkurt
bartubozkurt / operators_3.sql
Created June 11, 2021 17:54
Fetch name of cities that are in countries with IDs 1,4,7 or 8
SELECT name
FROM city
WHERE country_id IN (1,4,7,8);
@bartubozkurt
bartubozkurt / count.sql
Created June 11, 2021 18:00
Find out the number of cities
SELECT COUNT(*) FROM city;
@bartubozkurt
bartubozkurt / is_not_null.sql
Created June 11, 2021 18:02
Find out the number of cities with non-null ratings
SELECT COUNT(rating)
FROM city;
@bartubozkurt
bartubozkurt / distinct.sql
Created June 11, 2021 18:04
Find out the number of distinctive country values
SELECT COUNT(DISTINCT country_id)
FROM city;
@bartubozkurt
bartubozkurt / min_max.sql
Created June 11, 2021 18:09
Find out the smallest and the greatest counrt populations
SELECT MIN(population), MAX(population) FROM country;
@bartubozkurt
bartubozkurt / sum.sql
Created June 11, 2021 18:11
Find out the total population of cities in respective countries
SELECT country_id, SUM(population) FROM country;
@bartubozkurt
bartubozkurt / avg.sql
Created June 11, 2021 18:19
Find out the average rating for cities in respective countries if the average is above 3.0
SELECT country_id , AVG(rating)
FROM city
GROUP BY country_id
HAVING AVG(rating) > 3.0;
@bartubozkurt
bartubozkurt / single_value.sql
Created June 11, 2021 18:23
Finds cities with the same rating as Paris
SELECT name
FROM city
WHERE rating = (SELECT rating
FROM city
WHERE name = 'Paris');