##SQL Lab - October 9th, 2013
Download this SQLite database and write a SQL statement that:
Selects the names of all products that are not on sale. select * from products where "on_sale" = "t";
Selects the names of all products that cost less than $20.
select * from products where "price" < 20;
Selects the name and price of the most expensive product. select name from products order by price;
Selects the name and price of the second most expensive product. select name from products order by price limit 2;
Selects the name and price of the least expensive product. select name from products order by price desc limit 1;
Selects the names and prices of all products, ordered by price in descending order. select name from products order by price desc;
Selects the average price of all products. select price from products avgprice; (?)
Selects the sum of the price of all products. select avg(price) from products;
Selects the sum of the price of all products whose prices is less than $20. select sum(price) from products where "price" < 20;
Selects the id of the user anil. select id from users where "name" = "Anil Bridgpal";
Selects the names of all users whose names start with the letter "A". select * from users where "name" like 'A%';
Selects the number of users whose first names are "Jonathan". select count(name) from users where "name" like 'Jonathan%';
Selects the number of users who want a "Teddy Bear". select users.name from users inner join wishlists on users.id = wishlists."user_id" inner join products on wishlists."product_id" = "product_id" where products.name = "Teddy Bear";
Inserts a user with the name "Jonathan Postel" into the users table.
Selects the id of the user with the name "Jonathan Postel"?
Inserts a wishlist entry for the user with the name "Jonathan Postel" for the product "The Ruby Programming Language".
Updates the name of the "Jonathan Postel" user to be "Jon Postel".
Deletes the user with the name "Jon Postel".
Deletes the wishlist item for the user you just deleted.
BONUS QUESTIONS