Question bank
Pick an answer to see if you're right — with an explanation.
All topicsPythonSQL / MySQLData ScienceNumPyPandasMatplotlibMachine LearningDeep LearningArtificial IntelligenceLarge Language ModelsDjangoAPIsGit & GitHubPower BIExcelStatistics
SQL / MySQLMedium
Why does this filter usually prevent the use of an index on `created_at`?
SELECT * FROM orders WHERE YEAR(created_at) = 2026;
aYEAR() is not supported in MySQL
bApplying a function to the column hides it from the index; use a date range instead
cIndexes never work on DATETIME columns
dSELECT * disables all indexes
Explanation: Rewrite as `created_at >= '2026-01-01' AND created_at < '2027-01-01'` so the index can be range-scanned.
SQL / MySQLHard
Why does this query fail?
SELECT name FROM staff
WHERE salary > AVG(salary);
aAggregate functions are not allowed in WHERE; compare against a subquery such as (SELECT AVG(salary) FROM staff)
bAVG only works on integer columns
cThe query needs GROUP BY name first
dAVG must be spelled AVERAGE in MySQL
Explanation: WHERE is evaluated row by row before aggregation, so the average has to come from a subquery.
SQL / MySQLHard
Two cashiers may sell the last box at the same time. What prevents overselling inside a transaction?
aSELECT ... FOR UPDATE before the UPDATE
bAdding DISTINCT to the SELECT
cUsing READ UNCOMMITTED isolation
dRunning the UPDATE twice
Explanation: FOR UPDATE locks the selected row so the second transaction waits until the first commits.
SQL / MySQLHard
Why do customers with no orders disappear from this result?
SELECT c.name, o.id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.status = 'PAID';
aLEFT JOIN cannot be combined with WHERE
bThe WHERE test on the right table drops the NULL rows, so the join behaves like an INNER JOIN; move the condition into ON
cThe query is missing GROUP BY
dBecause `o.id` is selected
Explanation: Unmatched rows have NULL in every `o` column and `NULL = 'PAID'` is never true; putting the filter in the ON clause keeps those customers.
SQL / MySQLHard
With `SUM(revenue) OVER (PARTITION BY branch ORDER BY month)` and no explicit frame, what is computed?
aTotal revenue of the branch on every row
bRevenue of the current month only
cA running total from the branch's first month up to the current month
dTotal revenue across all branches
Explanation: With ORDER BY and no frame, the default frame is RANGE from UNBOUNDED PRECEDING to CURRENT ROW, giving a running total.