0% found this document useful (0 votes)
34 views7 pages

SQL(Coursera)

The document contains a series of graded quizzes and exam questions related to SQL and database concepts, covering topics such as basic SQL commands, relational database concepts, functions, sub-queries, and advanced SQL operations. It includes specific SQL queries and expected results for various problems, as well as definitions and explanations of key terms and functionalities in SQL. The quizzes assess knowledge on creating tables, using joins, stored procedures, and transaction management.

Uploaded by

harshitapril1167
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views7 pages

SQL(Coursera)

The document contains a series of graded quizzes and exam questions related to SQL and database concepts, covering topics such as basic SQL commands, relational database concepts, functions, sub-queries, and advanced SQL operations. It includes specific SQL queries and expected results for various problems, as well as definitions and explanations of key terms and functionalities in SQL. The quizzes assess knowledge on creating tables, using joins, stored procedures, and transaction management.

Uploaded by

harshitapril1167
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SQL: A Practical Introduction for Querying Databases

https://www.coursera.org/learn/sql-practical-introduction-for-querying-databases

Graded Quiz: Basic SQL

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:

SELECT DISTINCT(FIRSTNAME) FROM INSTRUCTOR

LEON

PAUL

JOE

3. What does the following SQL statement do?

UPDATE INSTRUCTOR SET LASTNAME = 'Brewster' WHERE LASTNAME = 'Smith'

Changes all rows for the instructor with a last name of Smith to have a last name of Brewster.

Graded Quiz: Relational DB Concepts and Tables

1. Which of the following statements about a database is/are correct?


A database is a logically coherent collection of data with some inherent meaning
2. Attributes of an entity become ________ in a table.
columns
3. The CREATE TABLE statement is a....

DDL statement

Graded Quiz: Refining Your Results

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

Graded Quiz: Functions, Sub-Queries, Multiple Tables

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

Project Evaluation (Quiz)

1. Which of the following is the correct SQL query for:


PROBLEM 1: Find the total number of crimes recorded in the Chicago crime table
➤ SELECT count(*) FROM chicago_crime_data

2. Which of the following is the correct SQL query for:


PROBLEM 2: Retrieve the first 10 rows from the CRIME table
➤ SELECT * FROM chicago_crime_data LIMIT 10

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%'

6. Which of the following is (are) the correct SQL query for:


PROBLEM 6: Which schools in Community Areas 10 to 15 are healthy school certified?
➤ SELECT name_of_school FROM CHICAGO_PUBLIC_SCHOOLS WHERE
Healthy_School_Certified = 'Yes' AND Community_Area_Number BETWEEN 10 AND 15

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

8. Which of the following is the correct SQL query for:


PROBLEM 8: List the top 5 Community Areas by average College Enrollment [number of
students]
➤ SELECT Community_Area_Name, AVG(College_Enrollment) AS AVG_ENROLLMENT FROM
CHICAGO_PUBLIC_SCHOOLS GROUP BY Community_Area_Name ORDER BY
AVG_ENROLLMENT DESC LIMIT 5

9. Which of the following is the correct SQL query for:


PROBLEM 9: Use a sub-query to determine which Community Area has the least value for
school Safety Score?
➤ SELECT COMMUNITY_AREA_NAME, SAFETY_SCORE FROM chicago_public_schools WHERE
SAFETY_SCORE = ( SELECT MIN(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

Graded Quiz: Views, Stored Procedures and Transactions

Question 1.A stored procedure can:


➤ All of the above
(Stored procedures can accept input, return results, and be written in multiple supported
languages depending on the DBMS.)

Question 2. What does ACID stand for?


➤ Atomic, Consistent, Isolated, Durable
Question 3. Which of the following SQL statements will create a view named EMP_VIEW with
an employee’s First name, last name, and ID, based on the EMPLOYEES table?
➤ CREATE VIEW EMP_VIEW (EMP_ID, FIRSTNAME, LASTNAME) AS SELECT EMP_ID, F_NAME,
L_NAME FROM EMPLOYEES;

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

Graded Quiz: JOIN operations

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 4.Which of the following are valid types of JOINs?

➤ LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN


Question 5. A FULL JOIN returns only the rows that match. (T/F)
➤ False

Graded Quiz: Advanced SQL for Data Engineers

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.

You might also like