Test your understanding of key SQL and Power BI concepts commonly asked in data analyst interviews, focusing on query writing, data modeling, and analytics scenarios.
Identifying the Second Highest Salary
Which SQL query would correctly find the second highest salary from an Employee table with a 'salary' column?
- SELECT MIN(salary) FROM Employee;
- SELECT salary FROM Employee WHERE salary = (SELECT MIN(salary) FROM Employee);
- SELECT salary FROM Employee LIMIT 2;
- SELECT SECOND(salary) FROM Employee;
- SELECT MAX(salary) FROM Employee WHERE salary u003C (SELECT MAX(salary) FROM Employee);
Difference Between WHERE and HAVING
In SQL, what is the main difference between the WHERE and HAVING clauses when filtering query results?
- WHERE and HAVING are always interchangeable.
- HAVING replaces WHERE in all queries.
- WHERE can be used after GROUP BY, HAVING cannot.
- WHERE is used for row filtering before grouping, while HAVING filters groups after aggregation.
- WHERE only works on numeric columns, HAVING works on text columns.
Understanding CTEs
What is a CTE (Common Table Expression) in SQL, and how is it typically defined?
- A custom table that is encrypted for security.
- A function that creates indexes automatically.
- A permanent database table used for storing metadata.
- A code block that only runs in stored procedures.
- A temporary result set defined with the WITH keyword, used for organizing complex queries.
SQL Joins Overview
Which join in SQL returns all records from the left table and only matching records from the right table?
- UNION JOIN
- INNER JOIN
- CROSS JOIN
- LEFT JOIN
- FULL JOIN
Handling NULL Values
What is a common SQL function to replace NULL values with a default, for example, turning NULL ages into 0?
- NULLIFY(age, 0)
- REPLACE(age, 0)
- SETNULL(age, 0)
- COALESCE(age, 0)
- FILLNULL(age, 0)
Union vs. Union All
When combining two datasets in SQL, which statement correctly describes UNION ALL compared to UNION?
- UNION ALL sorts the results automatically.
- UNION ALL only works on numeric data.
- UNION ALL cannot be used with SELECT statements.
- UNION ALL removes duplicates; UNION keeps all rows.
- UNION ALL keeps all duplicate rows; UNION removes duplicates.
Purpose of Relationships in Power BI
In Power BI data modeling, why do you create relationships between tables?
- To encrypt the dataset for security purposes.
- To enable data from different tables to be analyzed together, like linking Sales and Products tables.
- To automatically generate DAX measures.
- To visualize data in 3D charts.
- To increase the loading speed of the dashboard.
DirectQuery vs. Import Mode
Which option correctly describes the difference between DirectQuery and Import Mode in Power BI?
- DirectQuery is offline only; Import Mode updates in real-time.
- DirectQuery only works with Excel files.
- Import Mode supports more data sources than DirectQuery.
- DirectQuery creates static reports; Import Mode creates interactive dashboards.
- DirectQuery connects to live data sources, while Import Mode loads data into Power BI.
Role of Slicers in Power BI
How does a slicer typically function in a Power BI report?
- Filters visualizations based on user selections, such as showing sales by specific years.
- Downloads raw data from visuals.
- Sorts table columns automatically.
- Changes the color theme of the dashboard.
- Deletes data from the model.
Calculated Column vs. Measure
What is the main distinction between a calculated column and a measure in Power BI?
- Measures can only be used in tables, calculated columns only in charts.
- A measure is always stored in the database, but calculated columns are not.
- A calculated column is computed row by row in the data model, while a measure calculates results based on filters or aggregations at query time.
- There is no difference; the terms are interchangeable.
- Calculated columns require DAX, and measures do not.