You are on page 1of 11

UNIDAD 1

Let's Practice!

1. This statement will return an error. Please list why.

It's missing comma after "TrackID", and "Name"

2. In the ER diagram below, the infinity symbol is representing a "many" relationship and
the key is representing "one". Select all the tables that have a one-to-many
relationship.

Artist to Albums

Customers to Invoices

3. When using SQLite, what datatypes can you assign to a column when creating a new
table? Select all that apply.

TODO

4. Primary Keys must be unique values.

True

5. What is the query below missing in order to execute?

Select

Practice Simple Select Queries

1. Retrieve all the data from the tracks table. Who is the composer for track 18?
Select *
From Tracks
Where TrackId = 18;
AC/DC

2. Retrieve all data from the artists table. Look at the list of artists, how many artists are
you familiar with (there is no wrong answer here)?
Select Count (ArtistId)
From Artists;
275

3. Retrieve all data from the invoices table. What is the billing address for customer 31?
Select *
From Invoices
Where InvoiceId = 31;
194A Chain Lake Drive, Halifax, NS, CANADA B3S 1C5
9, Place Louis Barthou

4. Return the playlist id, and name from the playlists table. How many playlists are
there? Which would you classify is your favorite from this list?
Select distinct (Playlistid),
Name
From Playlists;
There are 18 playlists and my favorite is Grunge.
5. Return the Customer Id, Invoice Date, and Billing City from the Invoices table. What
city is associated with Customer ID number 42? What was the invoice date for the
customer in Santiago?
Select CustomerId,
InvoiceDate,
BillingCity
From Invoices
Where BillingCity = "Santiago";
The city of Customer ID number 42 is Bordeaux and the date of Customer in Santiago
are 2009-04-04, 2009-05-15, 2010-01-13, 2011-08-20, 2011-11-22, 2012-02-24, 2012-
10-14.

6. Return the First Name, Last Name, Email, and Phone, from the Customers table. What
is the telephone number for Jennifer Peterson?
Select FirstName,
LastName,
Email,
Phone
From Customers
Where LastName = "Peterson";
Jennifer Peterson's phone number is: +1 (604) 688-2255

7. Return the Track Id, Genre Id, Composer, Unit Price from the Tracks table. How much
do these tracks cost?
Select SUM(UnitPrice)
From Tracks;
3680.97
$0.99.

8. Select all the columns from the Playlist Track table and limit the results to 10 records.
How might this information be used?
Select *
From Playlist_track
Limit 10;
It could be used for analyze the PlaylistId Code number.

9. Select all the columns from the Media Types table and limit the results to 50 records.
What happened when you ran this query? Were you able to get all 50 records?
Select *
From Media_types
Limit 50;
It cannot possible because the table has only 5 rows.

10. Select all the columns from the Albums table and limit the results to 5 records. How
many columns are in the albums table?
Select *
From Albums
Limit 5;
There are 3 columns and the title is Plays Metallica By Four Cellos.
Module 1 Quiz

1. Select the jobs below that may use SQL in their work (select all that apply)

TODO

2. How does a data scientist and DBA differ in how they use SQL?

DBAs manage the database for other users.

3. Which of the following statements are true of Entity Relationship (ER) Diagrams?

They are usually a representation of a business process.

They usually are represented in a visual format.

They identify the Primary Keys

They show you the relationships between tables.

4. Select the query below that will retrieve all columns from the customers table.

SELECT * FROM customers

5. Select the query that will retrieve only the Customer First Name, Last Name, and
Company.

SELECT
FirstName
,LastName
,Company
FROM customers

6. The ER diagram below is depicting what kind of relationship between


the EMPLOYEES and CUSTOMERS tables?

One-to-many

7. The data model depicted in the ER diagram below could be described as a _________.

Relational Model

8. When using the "CREATE TABLE" command and creating new columns for that table,
which of the following statements is true?

You must assign a data type to each column

9. Look at the values in the two columns below. Based on the values in each column,
which column could potentially be used as a primary key?

Column 1

10. In order to retrieve data from a table with SQL, every SQL statement must contain?

SELECT
Module 1 Coding Questions

1. For all of the questions in this quiz, we are using the Chinook database. All of the
interactive code blocks have been setup to retrieve data only from this database.

Retrieve all the records from the Employees table.

Select* from Employees;

590 Columbia Boulevard West, Lethbridge, AB, CANADA T1K 5N8

2. Retrieve the FirstName, LastName, Birthdate, Address, City, and State from the
Employees table.

Select FirstName, LastName, Birthdate, Address, City, State from Employees;

Steve

3. Retrieve all the columns from the Tracks table, but only return 20 rows.
Select * from Tracks limit 20

375418
SEMANA 2

Module 2 Practice Quiz

1. For all the questions in this practice set, you will be using the Salary by Job Range
Table. This is a single table titled: salary_range_by_job_classification. This table
contains the following columns:
Yes, I am ready to begin.

2. Find the distinct values for the extended step. The code has been started for you, but
you will need to program the third line yourself before running the query.
SELECT
distinct (Extended_Step)
From salary_range_by_job_classification;

3. The code has been started for you, but you will need to add onto the last line of code
to get the correct answer.
Select
min(Biweekly_high_Rate)
From salary_range_by_job_classification
where biweekly_high_rate <> '$0.00'

15 TA MAL

4. What is the maximum biweekly high rate of pay (please include the dollar sign and
decimal point in your answer)? The code has been started for you, but you will need
to add onto the last line of code to get the correct answer.
SELECT
Max(Biweekly_high_Rate)
from salary_range_by_job_classification;

$9726.38

5. What is the pay type for all the job codes that start with '03'? The code has been
started for you, but you will need to program the fourth and fifth lines yourself before
running the query.
Select
Job_Code,
Pay_Type
from salary_range_by_job_classification
where Job_Code like '03%';

B
6. Run a query to find the Effective Date (eff_date) or Salary End Date (sal_end_date) for
grade Q90H0? The code has been started for you, but you will need to program the
third through the sixth lines yourself before running the query.
select
Eff_Date
,Sal_End_Date
from
salary_range_by_job_classification
where Grade = 'Q90H0';

12/26/2009 12:00:00 AM

7. Sort the Biweekly low rate in ascending order. There is no starter code, as you need to
write and run the query on your own. Hint: there are 4 lines to run this query.

SELECT DISTINCT (Step) From salary_range_by_job_classification;

NO

8. Write and run a query, with no starter code to answer this question: What Step are
Job Codes 0110-0400? Hint: there are 6 lines to run this query.
SELECT * From salary_range_by_job_classification where Job_Code IN ("0110", "0400");

9. What is the Biweekly High Rate minus the Biweekly Low Rate for job Code 0170?
SELECT (Biweekly_High_Rate - Biweekly_Low_Rate) AS MINUS From
salary_range_by_job_classification where Job_Code = "0170";

10. What is the Extended Step for Pay Types M, H, and D?


SELECT Extended_Step,Pay_Type From salary_range_by_job_classification where
Pay_Type IN ("M", "H", "D");

11. What is the step for Union Code 990 and a Set ID of SFMTA or COMMN?
SELECT * From salary_range_by_job_classification where Union_Code = "990" AND
(SETID = "SFMTA" or SETID = "COMMN");

Module 2 Quiz

1. Filtering data is used to do which of the following? (select all that apply)
TODO

2. You are doing an analysis on musicians that start with the letter “K”. Select the correct
query that would retrieve only the artists whose name starts with this letter.
SELECT name
FROM Artists
WHERE name LIKE ‘K%’;

3. A null and a zero value effectively mean the same thing. True or false?
False

4. Select all that are true regarding wildcards (Select all that apply.)
Wildcards take longer to run compared to a logical operator
Wildcards at the end of search patterns take longer to run

5. Select the statements below that ARE NOT true of the ORDER BY clause (select all that
apply).
Cannot sort by a column not retrieved
Can be anywhere in the select statement

6. Select all of the valid math operators in SQL (select all that apply).
TODO MENOS ^ (exponents)

7. Which of the following is an aggregate function? (select all that apply)


TODO MENOS DISTINCT

8. Which of the following is true of GROUP BY clauses? (Select all that apply.)
TODO

9. Select the true statement below.


HAVING filters after the data is grouped.

10. Which is the correct order of occurrence in a SQL statement?


select, from, where, group by, having

Module 2 Coding Assignment

1. Find all the tracks that have a length of 5,000,000 milliseconds or more.
SELECT COUNT(TrackId)
FROM TRACKS
WHERE Milliseconds >= 5000000

2. Find all the invoices whose total is between $5 and $15 dollars.
SELECT InvoiceID,Total
FROM Invoices
WHERE Total > 5 AND Total < 15

168

3. Find all the customers from the following States: RJ, DF, AB, BC, CA, WA, NY.
SELECT FirstName, LastName, Company, State
FROM Customers
WHERE State IN ('RJ','DF','AB','BC','CA','WA','NY')
Microsoft Corp

4. Find all the invoices for customer 56 and 58 where the total was between $1.00 and
$5.00.
SELECT CustomerId, InvoiceId, Total, InvoiceDate
FROM Invoices
WHERE CustomerID IN (56,58) AND
Total BETWEEN 1 AND 5;

10-27-2012

5. Find all the tracks whose name starts with 'All'.


SELECT TrackId, Name
FROM Tracks
WHERE Name LIKE 'All%'

15

6. Find all the customer emails that start with "J" and are from gmail.com.
SELECT CustomerId, Email
FROM Customers
WHERE Email LIKE J%@gmail.com

jubarnett@gmail.com

7. Find all the invoices from the billing city Brasília, Edmonton, and Vancouver and sort
in descending order by invoice ID.
SELECT InvoiceId, BillingCity, Total
FROM Invoices
WHERE BillingCity IN ('Brasilia','Edmonton','Vancouver')
ORDER BY InvoiceId DESC

$13.86

8. Show the number of orders placed by each customer (hint: this is found in the invoices
table) and sort the result by the number of orders in descending order.
SELECT CustomerId, COUNT(*) AS Orders
FROM Invoices
GROUP BY CustomerId
ORDER BY Orders DESC

9. Find the albums with 12 or more tracks.


SELECT AlbumId, Count(*) AS Ntracks
FROM Tracks
GROUP BY AlbumId
HAVING COUNT (*) >= 12

158
SEMANA 3

Practice Quiz - Writing Queries

1. 14
2. 40
3. NO
4. 14.85
5. 922880

Module 3 Quiz

1. Which of the following statements is true regarding subqueries?


Subqueries always process the innermost query first and the work outward.

2. If you can accomplish the same outcome with a join or a subquery, which one should
you always choose?
Joins are usually faster, but subqueries can be more reliable, so it depends on your
situation.

3. The following diagram is a depiction of what type of join?


Inner Join

4. Select which of the following statements are true regarding inner joins. (Select all that
apply)
Inner joins are one of the most popular types of joins use.
Performance will most likely worsen with the more joins you make.
There is no limit to the number of table you can join with an inner join.

5. Which of the following is true regarding Aliases? (Select all that apply.)
TODO

6. What is wrong with the following query?


The table name comes after the join condition

7. What is the difference between a left join and a right join?


The only difference between a left and right join is the order in which the tables are
relating.

8. If you perform a cartesian join on a table with 10 rows and a table with 20 rows, how
many rows will there be in the output table?
200

9. Which of the following statements about Unions is true? (select all that apply)
The UNION operator is used to combine the result-set of two or more SELECT
statements
The columns must also have similar data types
Each SELECT statement within UNION must have the same number of columns

10. Data scientists need to use joins in order to: (select the best answer)
Retrieve data from multiple tables.
Module 3 Coding Assignment

1. Using a subquery, find the names of all the tracks for the album "Californication".
Porcelain

2. Find the total number of invoices for each customer along with the customer's full
name, city and email.
frantisekw@jetbrains.com

3. Retrieve the track name, album, artistID, and trackID for all the albums.
Breaking The Rules

4. Retrieve a list with the managers last name, and the last name of the employees who
report to him or her.
King
Callahan

5. Find the name and ID of the artists who do not have albums.
Gilberto

6. Use a UNION to create a list of all the employee's and customer's first names and last
names ordered by the last name in descending order.
Taylor

7. See if there are any customers who have a different city listed in their billing city versus
their customer city.
No customers have a different city listed in their billing city versus customer city.

SEMANA 4

Module 4 Quiz

1. Which of the following are supported in SQL when dealing with strings? (Select all that
apply)
TODO

2. What will the result of the following statement be?


This will return an error

3. What are the results of the following query?


You won't get any results.

4. Case statements can only be used for which of the following statements (select all that
apply)?
TODO

5. Which of the following is FALSE regarding views?


Views will remain after the database connection has ended

6. You are only allowed to have one condition in a case statement. True or false?
False
7. Select the correct SQL syntax for creating a view.
CREATE VIEW
customers AS
SELECT *
FROM customers
WHERE Name LIKE '%I'

8. Profiling data is helpful for which of the following? (Select all that apply)
Understanding your data
Filter out unwanted data elements

9. What is the most important step before beginning to write queries?


Understanding your data

10. When debugging a query, what should you always remember to do first?
Start simple and break it down first

Module 4 Coding Questions

1. Pull a list of customer ids with the customer’s full name, and address, along with
combining their city and country together. Be sure to make a space in between these
two and make it UPPER CASE. (e.g. LOS ANGELES USA)
MOUNTAIN VIEW USA

2. Create a new employee user id by combining the first 4 letters of the employee’s first
name with the first 2 letters of the employee’s last name. Make the new field lower
case and pull each individual step to show your work.
RobeKi

3. Show a list of employees who have worked for the company for 15 or more years using
the current date function. Sort by lastname ascending.
Peacock

4. Profiling the Customers table, answer the following question.


Fax
Company
Postal Code

5. Find the cities with the most customers and rank in descending order.
London
Mountain View
São Paulo

6. Create a new customer invoice id by combining a customer’s invoice id with their first
and last name while ordering your query in the following order: firstname, lastname,
and invoiceID.
AstridGruber273
AstridGruber296
AstridGruber370

You might also like