Data Analytics

SQL - Aggregations and Grouping

COUNT, SUM, AVG, MIN, MAX, GROUP BY, HAVING, nested aggregate functions, COALESCE, CASE WHEN

20 interview questionsยท
Junior
1

Which SQL function counts the number of rows in a table?

Answer

COUNT is the SQL aggregate function that counts the number of rows returned by a query. COUNT(*) counts all rows including those with NULL values, while COUNT(column) only counts rows where the specified column is not NULL.

2

Which SQL function calculates the sum of values in a numeric column?

Answer

SUM is the aggregate function that adds up all non-NULL values in a numeric column. It is commonly used to calculate totals such as revenue, quantities sold, or any other cumulative value. If all values are NULL, SUM returns NULL.

3

What is the difference between COUNT(*) and COUNT(column)?

Answer

COUNT(*) counts all rows in the result, including those containing NULL values in any column. COUNT(column) only counts rows where the specified column has a non-NULL value. This distinction is essential when analyzing incomplete data.

4

Which SQL function returns the average value of a numeric column?

5

What is the role of the GROUP BY clause in an SQL query?

+17 interview questions

Master Data Analytics for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free