Data Analyst Interview Questions with Answers: Part-2 ๐ง
11. What is a subquery?
A subquery is a query nested inside another SQL query (like SELECT, INSERT, UPDATE, DELETE). It returns data used by the outer query.
Example:
SELECT name FROM students WHERE marks > (SELECT AVG(marks) FROM students);
12. Explain GROUP BY and HAVING clause
โข GROUP BY: Groups rows by a column's values for aggregation (SUM(), COUNT(), etc.)
โข HAVING: Filters aggregated results (like WHERE for groups)
Example:
SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) > 5;
13. What are window functions in SQL?
Window functions perform calculations across a set of rows related to the current row without collapsing rows.
Example: ROW_NUMBER(), RANK(), LEAD(), LAG()
SELECT name, department, RANK() OVER(PARTITION BY department ORDER BY salary DESC) FROM employees;
14. Difference between RANK(), DENSE_RANK(), ROW_NUMBER()
โข ROW_NUMBER(): Unique rank even if values are the same
โข RANK(): Skips ranks for ties
โข DENSE_RANK(): No rank gaps for ties
Example: If two people tie at 2nd place:
โข RANK: 1, 2, 2, 4
โข DENSE_RANK: 1, 2, 2, 3
โข ROW_NUMBER: 1, 2, 3, 4
15. What is a CTE in SQL?
CTE (Common Table Expression) is a temporary result set defined with WITH for better readability and reuse in a query.
Example:
WITH HighEarners AS (
SELECT name, salary FROM employees WHERE salary > 100000
)
SELECT * FROM HighEarners;
16. What is the difference between WHERE and HAVING?
โข WHERE: Filters before grouping (on individual rows)
โข HAVING: Filters after grouping (on aggregates)
Example:
SELECT department, COUNT(*) FROM employees
WHERE active = 1
GROUP BY department
HAVING COUNT(*) > 10;
17. Explain data types in SQL
Data types define the kind of data a column can store:
โข INT, FLOAT โ Numeric
โข VARCHAR, TEXT โ Strings
โข DATE, DATETIME โ Time values
โข BOOLEAN โ True/False values
18. How do you handle NULL values in SQL?
โข Use IS NULL or IS NOT NULL
โข Use functions like COALESCE() to replace NULLs
Example:
SELECT COALESCE(phone, 'Not Provided') FROM customers;
19. What are common data visualization tools?
โข Power BI
โข Tableau
โข Google Data Studio
โข Excel
โข Python libraries: Matplotlib, Seaborn, Plotly
20. When would you use a bar chart vs pie chart?
โข Bar chart: Compare multiple categories clearly
โข Pie chart: Show proportions of a whole (best for 2โ5 categories)
Bar charts are generally more accurate and readable.
๐ฌ Double Tap โฅ๏ธ For Part-3
Post #2469
9.75K
- โค 20
- ๐ 2
- ๐ฅ 2
- ๐ 1