PostgreSQL Database Quiz Questions

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

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

Q2
True / False

In PostgreSQL, you must use an aggregate function when using the GROUP BY clause.

Q3
True / False

In PostgreSQL, the GROUP BY clause can be used without any aggregate functions.

Q4
True / False

In PostgreSQL, you can group by multiple columns using the GROUP BY clause.

Q5
True / False

In PostgreSQL, the GROUP BY clause must include all non-aggregated columns in the SELECT statement.

Q6
True / False

In PostgreSQL, you can use column aliases in the GROUP BY clause.

Q7
True / False

In PostgreSQL, the GROUP BY clause can be used with the HAVING clause to filter groups based on aggregate values.

Q8
True / False

In PostgreSQL, the GROUP BY clause can be used in combination with window functions.

Q9
True / False

In PostgreSQL, you can group by expressions (e.g., GROUP BY date_trunc('month', timestamp)).

Q10
True / False

In PostgreSQL, using the GROUP BY clause improves performance by reducing the number of rows processed.

Q11
Single Choice

Which of the following SQL statements correctly uses the GROUP BY clause in PostgreSQL?

Q12
Single Choice

In PostgreSQL, what does the GROUP BY clause do in a SQL query?

Q13
Single Choice

Which of the following SQL queries will group the results by the category column and count the number of products in each category in PostgreSQL?

Q14
Single Choice

Given the following table sales in PostgreSQL:

SQL Code
product_id	sale_date	amount
1	2024-01-01	 100
2	2024-01-01	 150
1	2024-01-02 200
3	2024-01-02 	250
Which query will return the total sales amount for each sale_date?
Q15
Single Choice

What will be the output of the following PostgreSQL query if the table orders has multiple rows with the same customer_id?

SQL Code
SELECT customer_id, COUNT(*)
FROM orders
GROUP BY customer_id;
Q16
Single Choice

Consider a students table with columns student_id, name, class, and marks. Which of the following queries will correctly calculate the average marks for each class in PostgreSQL?

Q17
Single Choice

In PostgreSQL, how can you filter the results of a GROUP BY query to only include groups with a total sum greater than 1000?

SQL Code
SELECT category, SUM(amount)
FROM transactions
GROUP BY category
HAVING SUM(amount) > 1000;
Q18
Single Choice

Given the following PostgreSQL query, which groups the data by department and filters out departments with less than 5 employees, what will be the result?

SQL Code
SELECT department, COUNT(employee_id)
FROM employees
GROUP BY department
HAVING COUNT(employee_id) >= 5;
Q19
Single Choice

In PostgreSQL, what will the following query return?

SQL Code
SELECT country, AVG(salary)
FROM employees
GROUP BY country
ORDER BY AVG(salary) DESC;
Q20
Single Choice

How would you modify the following PostgreSQL query to include only those groups where the average age is greater than 30?

SQL Code
SELECT department, AVG(age)
FROM employees
GROUP BY department;
Q21
Multiple Choice

Which SQL scripts correctly group data by a specific column in PostgreSQL?

Q22
Multiple Choice

Identify the SQL scripts that correctly use GROUP BY with HAVING in PostgreSQL.

Q23
Multiple Choice

Determine the SQL scripts that correctly group data by multiple columns in PostgreSQL.

Q24
Multiple Choice

Select the SQL scripts that correctly group data and include non-aggregated columns in PostgreSQL.

Q25
Multiple Choice

Identify the SQL scripts that correctly use GROUP BY with COUNT in PostgreSQL.

Q26
Multiple Choice

Determine the SQL scripts that correctly group and filter data using WHERE and GROUP BY in PostgreSQL.

Q27
Multiple Choice

Select the SQL scripts that correctly use GROUP BY with DISTINCT in PostgreSQL.

Q28
Multiple Choice

Identify the SQL scripts that correctly use GROUP BY with multiple aggregate functions in PostgreSQL.

Q29
Multiple Choice

Determine the SQL scripts that correctly group data with subqueries in PostgreSQL.

Q30
Multiple Choice

Select the SQL scripts that correctly use GROUP BY with complex expressions in PostgreSQL.