SQL(Coursera)
SQL(Coursera)
https://www.coursera.org/learn/sql-practical-introduction-for-querying-databases
1. True or False: The INSERT statement can be used to insert multiple rows in a single statement.
True
2. Assume there exists an INSTRUCTOR table with several columns including FIRSTNAME,
LASTNAME, etc. Which of the following is the most likely result set for the following query:
LEON
PAUL
JOE
Changes all rows for the instructor with a last name of Smith to have a last name of Brewster.
DDL statement
1. 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%’
2. In a SELECT statement, which SQL clause controls how the result set is displayed?
ORDER BY clause
3. Which of the following can be used in a SELECT statement to restrict a result set?
All of the above
1. Which of the following queries will return the data for employees who belong to the
department with the highest value of department ID?
SELECT * FROM EMPLOYEES WHERE DEP_ID = ( SELECT MAX(DEPT_ID_DEP) FROM
DEPARTMENTS )
2. A DEPARTMENTS table contains DEP_NAME, and DEPT_ID_DEP columns and an
EMPLOYEES table contains columns called F_NAME and DEP_ID. We want to retrieve the
Department Name for each Employee. Which of the following queries will correctly
accomplish this?
SELECT E.F_NAME, D.DEP_NAME FROM EMPLOYEES, DEPARTMENTS WHERE E.DEP_ID
= D.DEPT_ID_DEP
3. You are writing a query that will give you the total cost to the Pet Rescue organization of
rescuing animals. The cost of each rescue is stored in the Cost column. You want the
result column to be called “Total_Cost”.
SELECT SUM(Cost) AS Total_Cost FROM PetRescue
3. Which of the following is the correct result value for the SQL query for:
PROBLEM 3: How many crimes involve an arrest
➤ 163
4. Given the subset of the Chicago crime dataset provided in the course, what are the correct
values in the result set for:
PROBLEM 4: Which unique types of crimes have been recorded at GAS STATION locations?
➤ CRIMINAL TRESPASS, MOTOR VEHICLE THEFT, ROBBERY, THEFT
5. Which of the following is the correct SQL query for:
PROBLEM 5: In the CENSUS_DATA table list all Community Areas whose names start with the
letter ‘B’.
➤ SELECT community_area_name FROM CENSUS_DATA WHERE community_area_name LIKE
'B%'
7. Which of the following is the correct SQL query [and result value] for:
PROBLEM 7: What is the average school Safety Score?
➤ SELECT avg(SAFETY_SCORE) FROM chicago_public_schools
10. Which of the following statement(s) is/are the correct SQL query for:
PROBLEM 10: [Without using an explicit JOIN operator] Find the Per Capita Income of the
Community Area which has a school Safety Score of 1.
➤ Both Options A and B are correct
Final Exam
1.The SELECT statement is called a ______, and the output we get from executing the query is
called a result set.
➤ Query
2.Which of the following SQL statements will delete the students with the last name Smith?
➤ DELETE FROM STUDENTS WHERE LAST_NAME = ‘Smith’
3.The primary key of a relational table uniquely identifies each _______ in a table.
➤ Row
4. What are the basic categories of the SQL language based on functionality?
➤ Both of the above
5. When querying a table called Teachers that contains a list of teachers and the city they
teach in, which of the following queries will return the number of teachers from each city?
➤ SELECT City, count(City) FROM Teachers GROUP BY City
6.You want to retrieve a list of books that have between 450 and 600 pages. Which clause
would you add to the following SQL statement: SELECT Title, Pages FROM Book
________________________________
➤ WHERE Pages >= 450 AND Pages <= 600
7. Which of the following queries will retrieve the HIGHEST value of SALARY in a table called
EMPLOYEES?
➤ SELECT MAX(SALARY) FROM EMPLOYEES
8.Which of the following queries will retrieve the last name of the employee who earns the
lowest salary?
➤ SELECT LAST_NAME FROM EMPLOYEES WHERE SALARY = (SELECT MIN(SALARY) FROM
EMPLOYEES)
9.A database cursor is a ___________ that enables traversal over the records in a database.
➤ Control object
10.To query data from tables in database a connection to the database needs to be
established. Which of the following is required to establish a connection with a relational
database from a Python notebook?
➤ All of the above
Question 4. Which of the following SQL statements will create a view that lists only the
employees in department number 7?
➤ CREATE VIEW EMP_VIEW (EMP_ID, FIRSTNAME, LASTNAME) AS SELECT EMP_ID, F_NAME,
L_NAME FROM EMPLOYEES WHERE DEP_ID = 7;
Question 5. You are developing an application that helps users transfer money from one bank
account to another. In tests, the source account is debited, but the target account is not
credited. Which of the following SQL commands undoes all the changes made during the
transfer to leave the database in a stable state?
➤ ROLLBACK
Question 1.A LEFT OUTER JOIN displays all the rows from the right table, and combines
matching rows from the left table. (T/F)
➤ False
Question 2. When using an OUTER JOIN, you must explicitly state what kind of OUTER JOIN
you want - a LEFT JOIN, a RIGHT JOIN, or a FULL JOIN. (T/F)
➤ True
Question 3.An INNER JOIN returns only the rows that match. (T/F)
➤ True
Question 1.Which two of the following statements would be the correct ways to use the Join
clause on the required tables from the database to generate this query?
➤ FROM chicago_socioeconomic_data a LEFT JOIN chicago_public_schools b ON
a.community_area_number = b.community_area_number
➤ FROM chicago_public_schools a RIGHT JOIN chicago_socioeconomic_data b ON
a.community_area_number = b.community_area_number
Question 2.How many rows were returned upon execution of this query (all crimes that took
place at a school)?
➤ 12
Question 3.Which of the following is the correct method of creating the required view?
➤ CREATE VIEW SCHOOL_DATA AS SELECT NAME_OF_SCHOOL AS School_Name, Safety_Icon
AS Safety_Rating, Family_Involvement_Icon AS Family_Rating, Environment_Icon AS
Environment_Rating, Instruction_Icon AS Instruction_Rating, Leaders_Icon AS
Leaders_Rating, Teachers_Icon AS Teachers_Rating FROM chicago_public_schools;
Question 4.Which of the following would be the correct query for this question (select school
name and leaders rating from the view)?
➤ SELECT School_Name, Leaders_Rating FROM SCHOOL_DATA;
Question 5. For creating this stored procedure, which of the following will be a requirement?
➤ All of them are required.
Question 6. Which one of the following is the correct query that goes in the stored procedure
statement?
➤ UPDATE CHICAGO_PUBLIC_SCHOOLS SET "Leaders_Score" = in_Leader_Score WHERE
"School_ID" = in_School_ID;
Question 7.Which of the following code snippets can be a part of the IF structure created for
this stored procedure?
➤ ELSEIF in_Leader_Score < 80 THEN UPDATE CHICAGO_PUBLIC_SCHOOLS SET
"Leaders_Icon" = 'Average';
Question 8.Which of the following is the correct way to execute the stored procedure
“UPDATE_LEADERS_SCORE”?
➤ CALL UPDATE_LEADERS_SCORE(610281, 50);
Question 9.What will be the nature of the edit that will be done to the stored procedure
(generic ELSE rollback)?
➤ A generic ELSE clause is added with the statement “ROLLBACK” to the IF ELSE structure.
Question 10. What will be the nature of the edit that will be done to the stored procedure
(commit work)?
➤ Add the statement “COMMIT WORK” after the IF ELSE statement structure.