databases and sql for data science with python coursera week 3 quiz answers

Practice Quiz

1. You want to retrieve a list of employees in alphabetical order of Lastname from the Employees table. Which SQL statement should you use?

  • SELECT * FROM Employees ORDER BY Lastname DESC;
  • SELECT * FROM Employees GROUP BY Lastname;
  • SELECT * FROM Employees ORDER BY Lastname;
  • SELECT * FROM Employees SORT BY Lastname;

2. Which keyword is used to set a condition for a GROUP BY clause?

  • HAVING
  • SELECT
  • ORDER BY
  • WHERE

3. You want to retrieve a list of authors from Australia, Canada, and India from the table Authors. Which SQL statement is correct?

  • SELECT * FROM Author WHERE Country LIST (‘CA’, ‘IN’);
  • SELECT * FROM Author WHERE Country BETWEEN(‘Australia’, ‘Canada’, ‘India’);
  • SELECT * FROM Author WHERE Country IN (‘Australia’, ‘Canada’, ‘India’);
  • SELECT * FROM Author IF Country (‘Australia’, ‘Canada’, ‘India’);

4. You want to retrieve a list of books priced above $10 and below $25 from the table Book. What are the two ways you can specify the range?

  • SELECT Title, Price FROM Book WHERE Price >= 10 and Price <= 25;
  • SELECT Title, Price FROM Book WHERE Price 10 to 25;
  • SELECT Title, Price FROM Book WHERE Price BETWEEN 10 and 25;
  • SELECT Title, Price FROM Book WHERE Price IN (10, 25);

5. You want to retrieve Salary information for an employee called Ed from the Employee table. You write the following statement:

SELECT Firstname, Lastname, Salary FROM Employees

You see all the employees listed, and it’s hard to find Ed’s information. Which clause should you add to reduce the number of rows returned?

  • GROUP BY Firstname = ‘Ed’;
  • WHERE Firstname = ‘Ed’;
  • ORDER BY Firstname;
  • WHERE Employees = ‘Ed’;

Graded Quiz: Refining Your Results

6. You want to select author's last name from a table, but you only remember the author’s last name starts with the letter B, which string pattern can you use?

  • SELECT lastname from author where lastname like ‘B#’
  • SELECT lastname from author where lastname like ‘B%’
  • SELECT lastname from author where lastname like ‘B$’
  • None of the above

7. In a SELECT statement, which SQL clause controls how the result set is displayed?

  • ORDER BY clause
  • ORDER IN clause
  • ORDER WITH clause

8. Which of the following can be used in a SELECT statement to restrict a result set?

  • HAVING
  • WHERE
  • DISTINCT
  • All of the above

Shuffle Q/A 1

Practice Quiz

9. Which of the following statements about built-in database functions is correct?

  • Built-in database functions may increase network bandwidth consumed.
  • Built-in database functions may increase processing time.
  • Built-in database functions must be called from a programming language like Python.
  • Built-in database functions reduce the amount of data that is retrieved.

10. Which of the following SQL queries would return the day of the week each dog was rescued?

  • SELECT RescueDate From PetRescue WHERE Animal = ‘Dog’;
  • SELECT DAYOFWEEK(RescueDate) From PetRescue WHERE Animal = ‘Dog’;
  • SELECT DAY(RescueDate) From PetRescue WHERE Animal = ‘Dog’;
  • SELECT DAYOFWEEK(RescueDate) From PetRescue;

Leave a Reply