SELECT price,
ROUND(AVG(downloads))
FROM fake_apps
GROUP BY price
HAVING count(name) > 9;
Back
Case
Front
SELECT name,
CASE
WHEN genre = 'romance' THEN 'Shit'
WHEN genre = 'comedy' THEN 'Probably Shit'
ELSE 'Probably Shit'
END AS 'Mood'
FROM movies;
(You get a column named mood, with entries shit, probably shit)
Back
AVG
Front
SELECT AVG(downloads)
FROM fake_apps;
Back
ROUND
Front
SELECT ROUND(AVG(price), 2)
FROM fake_apps;
Back
like2
Front
SELECT *
FROM movies
WHERE name LIKE 'The %';
Back
alter table
Front
ALTER TABLE celebs ADD COLUMN twitter_handle TEXT;
Back
between
Front
SELECT *
FROM movies
WHERE name BETWEEN 'D' AND 'G';
(selects all movies that start with letters D , E, F )
Back
where
Front
SELECT *
FROM movies
WHERE imdb_rating < 5;
Back
distinct
Front
SELECT DISTINCT genre
FROM movies;
Back
SUM
Front
SELECT SUM(downloads)
FROM fake_apps;
Back
AND
Front
SELECT *
FROM movies
WHERE year > 1985
AND (genre = 'romance' OR genre = 'comedy');
Back
GROUP BY 2
Front
SELECT category, SUM(downloads)
FROM fake_apps
GROUP BY category;
Back
order by
Front
SELECT name, year, imdb_rating as 'rating'
FROM movies
ORDER BY rating DESC;
Back
COUNT
Front
SELECT COUNT(*)
FROM fake_apps
WHERE price = 0;
Back
GROUP BY
Front
SELECT price, COUNT(*)
FROM fake_apps
WHERE downloads > 20000
GROUP BY price;
Back
CROSS JOIN
Front
SELECT month,
COUNT(*) as subscribers
FROM months
CROSS JOIN newspaper
WHERE month > start_month
AND month < end_month
GROUP BY month;
(shows number of subscribers for each month)
Back
update
Front
UPDATE celebs
SET age = 22
WHERE id = 1;
Back
With
Front
WITH previous_results AS (SELECT customer_id,
COUNT(subscription_id) as subscriptions
FROM orders
GROUP BY customer_id)
SELECT customers.customer_name,previous_results.subscriptions
FROM previous_results JOIN customers ON customers.customer_id = previous_results.customer_id;