InterviewStack.io LogoInterviewStack.io

Structured Query Language Fundamentals and Aggregation Questions

This topic covers core Structured Query Language fundamentals for analytical querying and reporting. Candidates should be able to write correct, readable, and maintainable SELECT queries with filtering using WHERE, sorting with ORDER BY, grouping with GROUP BY, and group filtering with HAVING. They should apply aggregate functions such as COUNT, COUNT DISTINCT, SUM, AVG, MIN, and MAX and understand how NULL values affect results, how empty result sets behave, and when to use different counting approaches. The scope includes date and time filtering, basic cohort segmentation, and common time based comparisons used to compute metrics such as daily active users, average revenue per user, and period over period comparisons. Candidates are expected to use basic joins and join predicates including inner joins and left joins, write simple subqueries and conditional expressions, and perform common data transformation and cleansing patterns to prepare data for analysis. Finally, this topic assesses query readability and maintainability practices such as aliasing and formatting, plus awareness of elementary performance considerations including index usage and avoiding unnecessary full table scans for entry to mid level analytical tasks.

HardTechnical
44 practiced
A GROUP BY on customer_id creates large temporary aggregates and memory pressure. Propose SQL and system strategies to mitigate this: use approximate aggregations, heavy-hitter pre-aggregation, sampling, or external sketch algorithms. Provide example SQL using APPROX_COUNT_DISTINCT or top-k pre-aggregation pattern.
MediumTechnical
56 practiced
You find emails in users table contain leading/trailing whitespace and inconsistent casing. Provide a SQL transformation to standardize emails (TRIM, LOWER), remove obviously invalid emails without '@', and deduplicate users keeping the most recent signup_date. Describe edge cases and how to safely run this in production.
EasyTechnical
56 practiced
Given users(user_id INT, signup_date DATE) and orders(order_id INT, user_id INT, amount DECIMAL, order_date DATE), write a query to list users who have placed at least one order in 2024. Use a subquery (IN or EXISTS) rather than a JOIN, and describe performance trade-offs between subquery and join in this simple membership case.
MediumTechnical
56 practiced
You have a large events table with an index on event_time. You need top 10 event_types by count over the last month. Which is better for performance: filtering in WHERE before GROUP BY or filtering aggregated groups with HAVING? Write the efficient SQL and explain reasoning about predicate pushdown and index usage.
HardTechnical
46 practiced
Compare date_trunc/month truncation and timezone handling across Postgres, BigQuery, and Snowflake when grouping by month. Provide example SQL for truncating to month and highlight pitfalls when dates are stored as strings. Recommend robust patterns to minimize cross-engine differences.

Unlock Full Question Bank

Get access to hundreds of Structured Query Language Fundamentals and Aggregation interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.