Week 2 exercises
Let's get some exercise!
But first! Download a copy of "DBeaver - Community Edition Opens in a new window".
This is a program that will make it easier to connect to remote databases (starting next week).
If it doesn't end up working for you, for whatever reason, that's okay. You will have other options.
Okay, now let's actually get some exercise!
Use the editor on this page to answer some questions from the Chinook database. Copy your answers into an SQL file. This is what you'll submit on Blackboard.
This is also a chance for you to practice formatting your code properly. And remember - if you have any questions, just ask me!
Questions:
- Get all the rows in the invoice table with an invoiceId of 400 or greater, and where the billingState is listed. Sort these rows so that the invoiceId goes from highest to lowest.
- Get 6 rows from the employee table. Sort the employees from oldest to youngest. Exclude the two oldest.
- Get a list of cities where the store has customers, without duplicates. Make all the city names lowercased.
- Get a list of all customers who have the letter 't' (either uppercase or lowercase) in either their first or last names. Include a column that lists the third letter of their last name.
- Get all of the rows from the artist table that contain an o with an ülaut ('ö'). In the results table, replace this character with a smiley face (':)')
- Get all results from the customer table. Replace null values in the state and fax columns with an empty string.
- Return all album titles longer than 20 characters. Only display the first twenty characters, and make all characters lowercase.
- Get all invoices from Berlin where the total is more than $5, and the invoices from Toronto where the total is more than $5. Sort from newest to oldest. Remember: if there is more than one way to write your code, you should stop and think about which way is best.
As a reminder, here are the names of the tables in the Chinook database: |
---|
Artist |
Album |
Customer |
Employee |
Genre |
Invoice |
InvoiceLine |
MediaType |
Playlist |
PlaylistTrack |
Track |