WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

SQL & Databases · Basic · question 10 of 100

What is the purpose of the GROUP BY clause in SQL?

📕 Buy this interview preparation book: 100 SQL & Databases questions & answers — PDF + EPUB for $5

The GROUP BY clause in SQL is used to group rows based on a specific criterion and calculate aggregate functions on each group. The GROUP BY clause is often used in conjunction with aggregate functions such as SUM, AVG, COUNT, MAX, and MIN.

Here is an example of a SQL statement that uses the GROUP BY clause:

SELECT department, AVG(salary)
FROM employees
GROUP BY department;

In this example, the GROUP BY clause is used to group employees by department and calculate the average salary for each department. The result set will contain one row for each department, along with the average salary for that department.

The purpose of the GROUP BY clause is to summarize and aggregate data based on a specific criterion. By using the GROUP BY clause, you can quickly calculate various metrics and statistics for different groups in your data set. For example, you can use the GROUP BY clause to calculate the total sales for each product category, the average rating for each movie genre, or the number of orders for each customer.

Without the GROUP BY clause, aggregate functions would calculate their results across the entire table or result set, without taking any grouping criteria into account. The GROUP BY clause allows you to specify one or more columns to group by, and each group will be treated as a separate entity for the purposes of calculating aggregate functions.

Overall, the GROUP BY clause is an essential tool for data analysis in SQL. It allows you to summarize and analyze data based on different grouping criteria, and derive insights and conclusions from large data sets.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic SQL & Databases interview — then scores it.
📞 Practice SQL & Databases — free 15 min
📕 Buy this interview preparation book: 100 SQL & Databases questions & answers — PDF + EPUB for $5

All 100 SQL & Databases questions · All topics