script.sql 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. INSERT INTO movies (title, runtime, genre, imdb_score, rating)
  2. VALUES('Howard the Duck', '110', 'Sci-Fi', '4.6', 'PG'),
  3. ('Lavalantula', '83', 'Horror', '4.7', 'TV-14'),
  4. ('Starship Troopers', '129', 'Sci-Fi', '7.2', 'PG-13'),
  5. ('Waltz With Bashir', '90', 'Documentary', '8.0', 'R'),
  6. ('Spaceballs', '96', 'Comedy', '7.1', 'PG'),
  7. ('Monsters Inc.', '92', 'Animation', '8.1', 'G'),
  8. ('The Shawshank Redemption', '142', 'Drama', '9.3', 'R'),
  9. ('The Godfather', '175', 'Drama', '9.2', 'R');
  10. SELECT *
  11. FROM movies
  12. WHERE genre = 'Sci-Fi';
  13. SELECT *
  14. FROM movies
  15. WHERE imdb_score >= '6.5';
  16. SELECT title, rating, runtime
  17. FROM movies
  18. WHERE rating = 'G' OR rating = 'PG' AND runtime < '100';
  19. SELECT AVG(runtime), genre
  20. FROM movies
  21. WHERE imdb_score < '7.5'
  22. GROUP BY genre;
  23. UPDATE movies
  24. SET rating = 'R'
  25. WHERE title = 'Starship Troopers';
  26. SELECT id, title, rating, genre
  27. FROM movies
  28. WHERE genre = 'Horror' OR genre = 'Documentary';
  29. SELECT AVG(imdb_score), MAX(imdb_score), MIN(imdb_score), rating
  30. FROM movies
  31. GROUP BY rating;
  32. SELECT AVG(imdb_score), MAX(imdb_score), MIN(imdb_score), rating
  33. FROM movies
  34. GROUP BY rating HAVING COUNT(*)>1;
  35. DELETE FROM movies
  36. WHERE rating = 'R';