330 likes | 464 Views
IS 324/325 Notes for Wednesday October 30, 2013. Class Notes Exam #1: grading not complete… will e-mail your grade to you on Friday or over the weekend Homework: graded on Friday or over the weekend… grades will be e-mailed to you Reading assignment for Nov 4 has been changed
E N D
IS 324/325 Notes for Wednesday October 30, 2013
Class Notes Exam #1: grading not complete… will e-mail your grade to you on Friday or over the weekend Homework: graded on Friday or over the weekend… grades will be e-mailed to you Reading assignment for Nov 4 has been changed No class on Wednesday, Nov 6
Let’s Get Our “SQL Feet” Wet Let’s play in the sandbox: http://edu.konagora.com/SQLsandbox.php#
Homework 1 Question 1 List the names and ages (in years) of all the actors who have not died. SELECT first_name, surname, 2013 - born as age FROM people WHERE died IS NULL ;
Homework 1 Question 2 List the names and the release year of all the movies that were released in 1956. SELECT title, year_released FROM movies WHERE year_released = 1956 ;
Homework 1 Question 3 List the names and the country code of all the French movies (the 2-letter identified for France is fr). SELECT title, country FROM movies WHERE country = "fr" ;
Homework 1 Question 4 List the names, the release year, and the country code for all the American or British movies released between 1940 and 1949 (the 2-letter identified for the United States is us and Great Britain is gb). SELECT title, year_released , country FROM movies WHERE year_released BETWEEN 1940 AND 1949 AND (country = "us" OR country = "gb" );
Homework 1 Question 5 List the names of all the movies that begin with the capital letter T. SELECT title FROM movies WHERE title LIKE "T%" ;
Practice Query (1a) Can you replace the "OR" clause below? SELECT title, year_released , country FROM movies WHERE year_released BETWEEN 1940 AND 1949 AND (country = "us" OR country = "gb" );
Practice Query (1b) Can you replace the "OR" claue below? SELECT title, year_released , country FROM movies WHERE year_released BETWEEN 1940 AND 1949 AND country IN ("us" , "gb" ) ;
Practice Query (2a) List all the movies that do not begin with a capital T
Practice Query (2b) List all the movies that do not begin with a capital T SELECT title FROM movies WHERE title NOT LIKE "T%" ;
Practice Query (3a) List all the movie titles and their release years in this format: XXXXXXXXX was released in YYYY.
Practice Query (3b) List all the movie titles and their release years in this format: XXXXXXXXX was released in YYYY. SELECT title || " was released in " || year_released || "." FROM movies ;
Practice Query (3c) List all the movie titles and their release years in this format: XXXXXXXXX was released in YYYY. SELECT title || " was released in " || year_released || "." AS Output_Sentence_Demo FROM movies ;
Practice Query (4a) List all the movie titles and their county in this format for French and British movies: XXXXXXXXX is a French movie. YYYYYYYYY is a British movie.
Practice Query (4b) List all the movie titles and their county in this format for French and British movies: XXXXXXXXX is a French movie. YYYYYYYYY is a British movie. SELECT title || " is a " || CASE country WHEN "fr" THEN "French" WHEN "gb" THEN "British" END || " movie." FROM movies ;
Practice Query (4c) SELECT title || " is a " || CASE country WHEN "fr" THEN "French" WHEN "gb" THEN "British" ELSE "country of unknown origin " END || "movie." FROM movies ;
Practice Query (5a) How do we remove the duplicates? SELECT country FROM movies ;
Practice Query (5b) How do we remove the duplicates? SELECT DISTINCT country FROM movies ;
Practice Query (6a) How do we capitalize the first letter of every word in the title? SELECT title FROM movies ;
Practice Query (6b) How do we capitalize the first letter of every word in the title? SELECT initcap (title) FROM movies ;
Practice Query (7a) Who died most recently?
Practice Query (7b) Who died most recently? SELECT first_name || " " || surname, died FROM people WHERE died = ( SELECT max(died) FROM people) ;
Practice Query (8a) How many movies are there?
Practice Query (8b) How many movies are there? SELECT COUNT (*) FROM movies ;
Practice Query (9a) How many movies are there by country? SELECT COUNT (*) FROM movies ;
Practice Query (9b) How many movies are there by country? SELECT COUNT (*), country FROM movies GROUP BY country ORDER BY 1 ;
Practice Query (9c) How many movies are there by country? Can I put them in order by "number of movies"? SELECT COUNT (*), country FROM movies GROUP BY 1 ; SELECT COUNT (*) AS Num_Movies, country FROM movies GROUP BY Num_Movies ;
Practice Query (9c) How many movies are there by country? Can I put them in order by "number of movies"? SELECT COUNT (*), country FROM movies GROUP BY country ORDER BY 1 ; SELECT COUNT (*) AS Num_Movies, country FROM movies GROUP BY country ORDER BY Num_Movies DESC ;
Practice Query (10a) What is the title of the oldest movie from each country?
Practice Query (10b) What is the title of the oldest movie from each country? SELECT country, title, MIN(year_released) FROM movies GROUP BY country ;
Big Data... Almost the Opposite of Relational Model What is it and why is it important? http://www.youtube.com/watch?v=7D1CQ_LOizA http://www.youtube.com/watch?v=R-bypPCIE9g