MySQL Database Quiz Questions

Course Name:MySQL
Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:PIVOT
Current Quiz Count:30
Progress
0%
Q1
True / False

MySQL supports the PIVOT operator natively.

Q2
True / False

To simulate a PIVOT in MySQL, you can use the CASE statement within an aggregate function.

Q3
True / False

You can use GROUP_CONCAT() to create a PIVOT-like output in MySQL.

Q4
True / False

MySQL’s GROUP BY clause can be used in conjunction with conditional aggregation to achieve a PIVOT-like result.

Q5
True / False

The UNION operator in MySQL can be used to simulate a PIVOT by stacking rows vertically.

Q6
True / False

You can use dynamic SQL in MySQL to create a PIVOT table with varying numbers of columns.

Q7
True / False

MySQL’s INSERT INTO ... SELECT statement can be used to prepare data for a PIVOT table by first creating a staging table.

Q8
True / False

Using the CROSS JOIN clause in MySQL is a recommended method for achieving PIVOT operations.

Q9
True / False

MySQL’s PREPARE and EXECUTE statements can be used to create a dynamic PIVOT query where column names are generated at runtime.

Q10
True / False

MySQL Workbench provides a built-in PIVOT feature for transforming data in a graphical interface.

Q11
Single Choice

Which MySQL function can be used in combination with CASE to simulate a PIVOT table?

Q12
Single Choice

In a basic PIVOT operation, what is the role of the GROUP BY clause in MySQL?

Q13
Single Choice

Which keyword is typically used to conditionally aggregate data in a MySQL PIVOT-like query?

Q14
Single Choice

Which SQL query would you use to PIVOT this data to show SalesAmount by Product and Quarter?

SQL Code
Given the following table Sales:
Product	Quarter	SalesAmount
A	 Q1	 1000
A	 Q2	 1500
B	 Q1	 2000
B	 Q2	 2500
Q15
Single Choice

Which of the following queries can be used to simulate a PIVOT operation on a Product table with Category and Price columns, to get the total price for each category?

Q16
Single Choice

In the context of a PIVOT-like operation in MySQL, which statement about using UNION ALL is correct?

Q17
Single Choice

Write a SQL query to PIVOT this data to show the total Amount for each Status by Customer.

SQL Code
You have the following Orders table:

OrderID	Customer	Status	Amount
1	Alice	Pending	100
2	Bob	Shipped	200
3	Alice	Shipped	150
4	Bob	Pending	250
Q18
Single Choice

If you encounter performance issues while executing a complex PIVOT operation in MySQL, which indexing strategy could help optimize the query?

Q19
Single Choice

In a MySQL PIVOT simulation, what happens if the GROUP BY column contains NULL values?

Q20
Single Choice

Consider a MySQL query that pivots a table sales based on the region and month columns. The query uses a CASE statement to conditionally sum the sales data. If the query performs slowly on a large dataset, which of the following optimization techniques could improve performance?

Q21
Multiple Choice

Which SQL query uses PIVOT to transform rows into columns, aggregating sales data by product and quarter?

SQL Code
SELECT product_name,
SUM(CASE WHEN quarter = 'Q1' THEN sales ELSE 0 END) AS Q1_sales,
SUM(CASE WHEN quarter = 'Q2' THEN sales ELSE 0 END) AS Q2_sales,
SUM(CASE WHEN quarter = 'Q3' THEN sales ELSE 0 END) AS Q3_sales,
SUM(CASE WHEN quarter = 'Q4' THEN sales ELSE 0 END) AS Q4_sales
FROM sales_data
GROUP BY product_name;
Q22
Multiple Choice

Identify the SQL query that uses PIVOT to summarize employee attendance data, showing the total days attended per month.

SQL Code
SELECT employee_name,
SUM(CASE WHEN month = 'January' THEN days_attended ELSE 0 END) AS Jan_days,
SUM(CASE WHEN month = 'February' THEN days_attended ELSE 0 END) AS Feb_days,
SUM(CASE WHEN month = 'March' THEN days_attended ELSE 0 END) AS Mar_days
FROM attendance_data
GROUP BY employee_name;
Q23
Multiple Choice

Which SQL query uses PIVOT to show the total sales for each product across different regions?

SQL Code
SELECT product_name,
SUM(CASE WHEN region = 'North' THEN sales ELSE 0 END) AS North_sales,
SUM(CASE WHEN region = 'South' THEN sales ELSE 0 END) AS South_sales,
SUM(CASE WHEN region = 'East' THEN sales ELSE 0 END) AS East_sales,
SUM(CASE WHEN region = 'West' THEN sales ELSE 0 END) AS West_sales
FROM sales_data
GROUP BY product_name;
Q24
Multiple Choice

Determine the SQL query that uses PIVOT to display the total number of orders for each product across different years.

SQL Code
SELECT product_name,
SUM(CASE WHEN year = 2021 THEN order_count ELSE 0 END) AS Orders_2021,
SUM(CASE WHEN year = 2022 THEN order_count ELSE 0 END) AS Orders_2022,
SUM(CASE WHEN year = 2023 THEN order_count ELSE 0 END) AS Orders_2023
FROM order_data
GROUP BY product_name;
Q25
Multiple Choice

Which SQL query uses PIVOT to aggregate sales data, showing the total revenue generated by each salesperson across different months?

SQL Code
SELECT salesperson,
SUM(CASE WHEN month = 'January' THEN revenue ELSE 0 END) AS Jan_revenue,
SUM(CASE WHEN month = 'February' THEN revenue ELSE 0 END) AS Feb_revenue,
SUM(CASE WHEN month = 'March' THEN revenue ELSE 0 END) AS Mar_revenue
FROM sales_data
GROUP BY salesperson;
Q26
Multiple Choice

Which SQL query uses PIVOT to display the total hours worked by employees in different departments across various projects?

SQL Code
SELECT department,
SUM(CASE WHEN project = 'Project A' THEN hours_worked ELSE 0 END) AS ProjectA_hours,
SUM(CASE WHEN project = 'Project B' THEN hours_worked ELSE 0 END) AS ProjectB_hours,
SUM(CASE WHEN project = 'Project C' THEN hours_worked ELSE 0 END) AS ProjectC_hours
FROM work_data
GROUP BY department;
Q27
Multiple Choice

Identify the SQL query that uses PIVOT to show the total number of units sold per product across different store locations.

SQL Code
SELECT product_name,
SUM(CASE WHEN location = 'Store A' THEN units_sold ELSE 0 END) AS StoreA_units,
SUM(CASE WHEN location = 'Store B' THEN units_sold ELSE 0 END) AS StoreB_units,
SUM(CASE WHEN location = 'Store C' THEN units_sold ELSE 0 END) AS StoreC_units
FROM sales_data
GROUP BY product_name;
Q28
Multiple Choice

Which SQL query uses PIVOT to aggregate the number of hours logged by employees on different tasks?

SQL Code
SELECT employee_name,
SUM(CASE WHEN task = 'Task 1' THEN hours_logged ELSE 0 END) AS Task1_hours,
SUM(CASE WHEN task = 'Task 2' THEN hours_logged ELSE 0 END) AS Task2_hours,
SUM(CASE WHEN task = 'Task 3' THEN hours_logged ELSE 0 END) AS Task3_hours
FROM time_log
GROUP BY employee_name;
Q29
Multiple Choice

Determine the SQL query that uses PIVOT to display the average test scores for students across different subjects.

SQL Code
SELECT student_name,
AVG(CASE WHEN subject = 'Math' THEN score ELSE 0 END) AS Math_avg,
AVG(CASE WHEN subject = 'Science' THEN score ELSE 0 END) AS Science_avg,
AVG(CASE WHEN subject = 'History' THEN score ELSE 0 END) AS History_avg
FROM test_scores
GROUP BY student_name;
Q30
Multiple Choice

Which SQL query uses PIVOT to summarize sales data, showing the total quantity sold per product across different months?

SQL Code
SELECT product_name,
SUM(CASE WHEN month = 'January' THEN quantity ELSE 0 END) AS Jan_quantity,
SUM(CASE WHEN month = 'February' THEN quantity ELSE 0 END) AS Feb_quantity,
SUM(CASE WHEN month = 'March' THEN quantity ELSE 0 END) AS Mar_quantity
FROM sales_data
GROUP BY product_name;