Sharpen your understanding of common SQL interview questions focused on purchase data analysis, filtering, group aggregation, and date logic. Perfect for candidates targeting data science, analytics, and engineering roles who want to master key SQL concepts tested in technical interviews.
Which SQL clause should be used to restrict the results to purchases made exactly during the last one month from today?
Explanation: The WHERE clause filters rows based on the purchase date to ensure only those made in the last month are considered. ORDER BY only sorts results, not filters them. GROUP BY is for aggregating data based on columns, not for filtering by date. HAVING is used to filter after aggregation, and the condition shown does not find purchases from the last month.
A purchase is considered successful if it is not returned within a week. Which SQL condition accurately selects such purchases?
Explanation: Successful purchases are those with no return or with a return date after one week, which is properly captured by the given condition. The second option only finds purchases returned quickly, not successful ones. The third only finds returned purchases, missing out those never returned. The last option checks for same-day purchase and return, which is incorrect.
To find customers with multiple successful purchases, which SQL clause is essential for counting the number of purchases per customer?
Explanation: GROUP BY is used to aggregate purchases by customer so you can count how many each has. JOIN is for combining tables, not grouping. ORDER BY COUNT(*) just sorts but does not count or group. LIMIT restricts the number of returned rows and does not perform grouping.
Which SQL function helps identify customers with more than one successful purchase in a filtered dataset?
Explanation: COUNT(*) tallies the number of purchases per customer, letting you filter for those with multiple. MAX() finds the largest value, which is not suitable here. ROUND() is a mathematical function unrelated to counting rows. LEN() measures string length and is not useful for counting purchases.
After grouping by customer_id, which clause allows you to select only customers with more than one successful purchase?
Explanation: HAVING is the correct clause for filtering groups based on aggregate results like COUNT(*). WHERE cannot use aggregated values directly. ORDER BY just changes the result order. SELECT COUNT(*) u003E 1 is not valid SQL syntax for filtering.
Which SQL operator checks if the return_date field is missing for a purchase?
Explanation: IS NULL checks for missing or null values in a field, perfectly suited for this scenario. '= NULL' is invalid syntax and will not work correctly. 'NOT NULL' is a keyword for checking presence, not absence, and 'LIKE NULL' is not a valid operation.
When ensuring both date and successful purchase conditions, which keyword should be used to combine these in a WHERE clause?
Explanation: AND combines multiple conditions so both must be true for a row to be included, which suits filtering by purchase date and return criteria. OR allows either condition, which is not correct for this case. BY is used elsewhere, like GROUP BY, not in conditional expressions. FROM defines data sources, unrelated to condition logic.
Given a table with purchase_id, customer_id, purchase_date, and return_date, which field is most suitable for identifying unique transactions?
Explanation: purchase_id uniquely identifies each transaction, making it ideal for this purpose. customer_id identifies individuals, not transactions. purchase_date and return_date may repeat for different transactions and are unsuitable as unique identifiers.
Which SQL function is commonly used to obtain today's date for filtering recent purchases?
Explanation: CURRENT_DATE retrieves today's date in SQL, standard for date calculations. NEW_DATE and DATE_NOW are not standard SQL functions. GET_DATE() is used in some systems but not standard, so CURRENT_DATE is reliably cross-platform.
If the return_date for a purchase is NULL, what does this indicate about the purchase status?
Explanation: A NULL in the return_date means the item has not been returned. A same-day return would show an actual date value. purchase_id missing would occur in a different field, and an item returned before purchase is impossible and illogical.