SQL Dialects and Built-in Functions Questions
Portability and idiom differences across SQL engines (PostgreSQL, Redshift, MySQL, SQL Server, and others), plus fluent use of built-in string, date/time, and type-conversion functions. Covers dialect-specific syntax, function availability, and writing queries that behave predictably across platforms. Relevant when candidates move between database ecosystems.
Write a SQL stored function (or parametrized query) that given an input_date and a fiscal_start_month (1-12) returns the start_date and end_date of the fiscal quarter that contains input_date. Show the logic and discuss edge cases like leap-year February and inputs on exact boundary dates.
During the fall DST transition (clocks go back), some timestamps are ambiguous (e.g., '2023-11-05 01:30' occurs twice in 'America/New_York'). As a BI engineer, describe how you'd detect, store, and disambiguate such events so reporting doesn't double-count or misorder events. Include storage recommendations and any data model changes.
Write SQL to compute the billing due date for customers where the billing day is the 31st of the month. If the target month doesn't have that day, bill on the last day of the month. Use PostgreSQL or MySQL and explain behavior for February (leap and non-leap years).
Given events(event_id, payload JSON) where payload contains an array of items, write queries to flatten and aggregate counts per item.category in PostgreSQL (jsonb_array_elements), BigQuery (UNNEST(JSON_EXTRACT_ARRAY)), and Snowflake (LATERAL FLATTEN). Discuss performance and when to normalize JSON into relational tables instead.
PostgreSQL supports SELECT DISTINCT ON (col) to pick the first row per group. Given orders(order_id, customer_id, order_date), write the Postgres DISTINCT ON query to select the latest order per customer, and then write a portable alternative using ROW_NUMBER() OVER (PARTITION BY ...) that works in SQL Server and BigQuery. Explain performance trade-offs.
Unlock Full Question Bank
Get access to all 46 SQL Dialects and Built-in Functions interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.