MySQL Database Quiz Questions

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

In MySQL, the GROUP BY clause is used to group rows that have the same values in specified columns.

Q2
True / False

In MySQL, you must use the GROUP BY clause with an aggregate function like SUM or COUNT.

Q3
True / False

MySQL allows you to use the GROUP BY clause with multiple columns.

Q4
True / False

In MySQL, the HAVING clause can only be used with the GROUP BY clause.

Q5
True / False

The HAVING clause can be used without GROUP BY, although it is typically used to filter groups of rows formed by GROUP BY.

Q6
True / False

When using GROUP BY in MySQL, the order of the grouped columns does not affect the result set

Q7
True / False

In MySQL, the GROUP BY clause always returns results in the order specified by the GROUP BY columns.

Q8
True / False

MySQL’s GROUP BY allows the use of expressions and functions in the list of columns to group by.

Q9
True / False

In MySQL, using GROUP BY with large datasets can impact performance significantly, and indexing the grouped columns can help mitigate this.

Q10
True / False

In MySQL, it is a best practice to include only columns in the SELECT clause that are either part of the GROUP BY clause or used with an aggregate function when using GROUP BY.

Q11
Single Choice

Which of the following clauses is used in MySQL to group rows that have the same values in specified columns?

Q12
Single Choice

What will be the result of the following SQL query?

SQL Code
SELECT department, COUNT(*)
FROM employees
GROUP BY department;
Q13
Single Choice

In MySQL, can you use the GROUP BY clause without any aggregate functions?

Q14
Single Choice

Given the following query, what will be the output?

SQL Code
SELECT city, SUM(sales)
FROM store_sales
GROUP BY city;
Q15
Single Choice

Which of the following is true about using GROUP BY with the HAVING clause in MySQL?

Q16
Single Choice

What will the following query return?

SQL Code
SELECT product, COUNT(*)
FROM orders
WHERE order_date > '2024-01-01'
GROUP BY product
HAVING COUNT(*) > 10;
Q17
Single Choice

Consider the table sales with columns product_id, sale_date, and amount. What does the following query accomplish?

SQL Code
SELECT product_id, MAX(amount)
FROM sales
GROUP BY product_id
ORDER BY MAX(amount) DESC;
Q18
Single Choice

What does the following query return in a table with columns department, employee, and salary?

SQL Code
SELECT department, SUM(salary) AS total_salary
FROM employees
GROUP BY department
HAVING total_salary > 100000;
Q19
Single Choice

How does MySQL handle NULL values when using GROUP BY?

Q20
Single Choice

Given the following table orders with columns order_id, customer_id, and order_total, what does the query below accomplish

SQL Code
SELECT customer_id, COUNT(order_id) AS total_orders
FROM orders
GROUP BY customer_id
HAVING total_orders = (
 SELECT MAX(total_orders)
 FROM (
 SELECT COUNT(order_id) AS total_orders
 FROM orders
 GROUP BY customer_id
 ) AS order_counts
);
Q21
Multiple Choice

Which query groups the records in the 'employees' table by 'department_id' and calculates the average salary for each department?

SQL Code
SELECT department_id, AVG(salary) AS avg_salary
FROM employees
GROUP BY department_id;
Q22
Multiple Choice

Identify the correct SQL query that groups records in the 'orders' table by 'order_date' and counts the number of orders for each date.

SQL Code
SELECT order_date, COUNT(order_id) AS order_count
FROM orders
GROUP BY order_date;
Q23
Multiple Choice

Which query groups records in the 'products' table by 'category_id' and sums the 'price' for each category?

SQL Code
SELECT category_id, SUM(price) AS total_price
FROM products
GROUP BY category_id;
Q24
Multiple Choice

Determine the correct SQL query that groups records in the 'customers' table by 'country' and finds the maximum 'revenue' for each country.

SQL Code
SELECT country, MAX(revenue) AS max_revenue
FROM customers
GROUP BY country;
Q25
Multiple Choice

Which SQL query groups records in the 'inventory' table by 'item_code' and counts the distinct 'locations' for each item?

SQL Code
SELECT item_code, COUNT(DISTINCT location) AS location_count
FROM inventory
GROUP BY item_code;
Q26
Multiple Choice

Which query correctly groups records in the 'sales' table by 'sales_rep' and calculates the total 'sales_amount' for each representative?

SQL Code
SELECT sales_rep, SUM(sales_amount) AS total_sales
FROM sales
GROUP BY sales_rep;
Q27
Multiple Choice

Determine the correct SQL query that groups records in the 'transactions' table by 'transaction_date' and calculates the average 'transaction_amount' for each date.

SQL Code
SELECT transaction_date, AVG(transaction_amount) AS avg_amount
FROM transactions
GROUP BY transaction_date;
Q28
Multiple Choice

Which SQL query groups records in the 'projects' table by 'project_manager' and finds the minimum 'budget' for each manager?

SQL Code
SELECT project_manager, MIN(budget) AS min_budget
FROM projects
GROUP BY project_manager;
Q29
Multiple Choice

Identify the correct query that groups records in the 'clients' table by 'region' and counts the number of distinct 'client_id' for each region.

SQL Code
SELECT region, COUNT(DISTINCT client_id) AS client_count
FROM clients
GROUP BY region;
Q30
Multiple Choice

Which SQL query correctly groups records in the 'students' table by 'grade' and calculates the total number of students in each grade?

SQL Code
SELECT grade, COUNT(student_id) AS total_students
FROM students
GROUP BY grade;