SQL Basics CHEAT SHEAT
SQL Basics CHEAT SHEAT
Sample Data
airbnb_listings
SELECT *
FROM airbnb_listings
mE Return the city column from the table !E Get the first 5 rows from the
SELECT city
airbnb_listings table
FROM airbnb_listings; SELECT *
FROM airbnb_listings
SELECT city
FROM airbnb_listings
FROM airbnb_listings
=! Get all the listings based in the ‘USA’ and in
WHERE number_of_rooms >= 3; ‘France’
SELECT *
FROM airbnb_listings
! Get all the listings where the city starts with
WHERE number_of_rooms > 3; ‘j’ and where the city does not end in ‘t’
SELECT *
FROM airbnb_listings
FROM airbnb_listings
FROM airbnb_listings
FROM airbnb_listings
FROM airbnb_listings
FROM airbnb_listings
GROUP BY country;
SELECT AVG(number_of_rooms)
ORDER BY avg_rooms ASC;
FROM airbnb_listings;
For Japan and the USA, get the average
Get the listing with the highest number of rooms number of rooms per listing in each country
across all listings
SELECT country, MAX(number_of_rooms)
SELECT MAX(number_of_rooms)
FROM airbnb_listings
GROUP BY country;
§ Get the listing with the lowest number of rooms
across all listings Get the number of cities per country, where
SELECT MIN(number_of_rooms)
there are listings
FROM airbnb_listings; SELECT country, COUNT(city) AS
number_of_cities
GROUP BY country;
Ë Get the total number of rooms for each country
Get all the years where there were more than
SELECT country, SUM(number_of_rooms)
100 listings per year
FROM airbnb_listings
FROM airbnb_listings
*Source: Internet
Get the average number of rooms for each country GROUP BY year_listed
FROM airbnb_listings
GROUP BY country;