Code Examples Flashcards
SELECT COUNT(*)
FROM table_name;
This counts all the rows in the Table.
SELECT SUM(downloads)
FROM table_name;
This adds all values in the downloads column of the Table.
SELECT MAX(downloads)
FROM table_name;
This returns the largest value in the downloads column of the Table.
SELECT MIN(downloads)
FROM table_name;
This returns the smallest value in the downloads column of the Table.
SELECT AVG(downloads)
FROM table_name;
This returns the average number of downloads column of the Table.
SELECT ROUND(price, 0)
FROM table_name;
This rounds the values in the price column Table to 0 decimal places.
SELECT year,
AVG(imdb_rating)
FROM movies
GROUP BY year
ORDER BY year;
This returns the the year and average imdb_rating values that are grouped and ordered by the year.
SELECT ROUND(imdb_rating),
COUNT(name)
FROM movies
GROUP BY 1
GROUP BY 1;
This rounds the imdb_rating values and counts all the columns in name from the Table movies and the values are grouped by the first column.
SELECT year,
genre,
COUNT(name)
FROM movies
GROUP BY 1, 2
HAVING COUNT(name) > 10;
This selects the year, genre, and counts the name column from the movies Table, Grouping them by column 1 and column 2 but only counting the name values that are greater than 10.
SELECT orders.order_id,
customers.customer_name
FROM orders
JOIN customers
ON orders.customer_id = customers.customer_id
INNER JOIN
SELECT *
FROM table1
LEFT JOIN table2
ON table1.c2 = table2.c2;
LEFT JOIN
SELECT shirts.shirts_color,
pants.pants_color
FROM shirts
CROSS JOIN pants;
CROSS JOIN
SELECT *
FROM table1
UNION
SELECT *
FROM table2;
UNION
WITH previous_results AS (
SELECT …..
)
SELECT *
FROM previous_results
JOIN customers
ON _____ = ______;
WITH
What is a PRIMARY KEY?
Special columns