Candidate telemetry diagnostic, error autopsy, and step-by-step query construction walkthrough.
Live aggregated metrics across candidate sandbox attempts
30 solved
First attempt fail
Evaluated submissions
Median time to solve
Unlocked answer
Pivot revenue per billing country across days of the week — useful for spotting weekend-heavy markets.
| Column | Type |
|---|---|
| InvoiceId | INTEGER (PK) |
| CustomerId | INTEGER (FK) |
| InvoiceDate | TIMESTAMP NOT NULL |
| BillingCountry | TEXT |
| Total | NUMERIC(10,2) NOT NULL |
BillingCountry, produce 7 columns: Sun, Mon, Tue, Wed, Thu, Fri, Sat — each the rounded sum of Total for invoices on that weekdayTotalRevenue (rounded), WeekendShare = (Sun + Sat) / TotalRevenue × 100, rounded to 2Your query should return 24 rows with 10 columns: | billingcountry | sun | mon | tue | wed | thu | fri | sat | totalrevenue | weekendshare | |----------------|-------|-------|------|-------|-------|-------|-------|--------------|--------------| | France | 18.84 | 25.75 | 1.98 | 11.88 | 47.52 | 1.98 | 87.15 | 195.1 | 54.33 | | Denmark | 1.98 | 14.85 | 1.98 | 3.96 | 0.0 | 0.0 | 14.85 | 37.62 | 44.74 | | Australia | 14.85 | 1.98 | 3.96 | 0.0 | 0.0 | 14.85 | 1.98 | 37.62 | 44.74 | | Argentina | 14.85 | 1.98 | 3.96 | 0.0 | 0.0 | 14.85 | 1.98 | 37.62 | 44.74 | | Brazil | 15.84 | 19.8 | 1.98 | 26.73 | 45.56 | 16.83 | 63.36 | 190.1 | 41.66 | | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
Double-counting metrics by using COUNT(*) after joining parent and child tables. When joining an invoice table with an invoice lines table, a single invoice multiplies across all its line items, causing COUNT(invoice_id) to return line counts instead of unique invoice counts.
Interviewers check whether you notice 1-to-many cardinality multiplication and use COUNT(DISTINCT col) or pre-aggregate child records before joining.
Construct the solution logically from first principles to avoid typical edge case pitfalls.
Identify the base table and apply preliminary WHERE filters.
FROM TableName WHERE is_active = true
Group by primary business keys and compute aggregate expressions.
SELECT category, COUNT(DISTINCT item_id) AS total_items, SUM(amount) AS revenue GROUP BY category
Order by specified metrics descending and apply limit clauses.
ORDER BY revenue DESC LIMIT 10;
WITH per_invoice AS (
SELECT BillingCountry,
EXTRACT(DOW FROM InvoiceDate)::int AS dow,
Total
FROM Invoice
)
SELECT BillingCountry,
ROUND(SUM(CASE WHEN dow = 0 THEN Total ELSE 0 END), 2) AS Sun,
ROUND(SUM(CASE WHEN dow = 1 THEN Total ELSE 0 END), 2) AS Mon,
ROUND(SUM(CASE WHEN dow = 2 THEN Total ELSE 0 END), 2) AS Tue,
ROUND(SUM(CASE WHEN dow = 3 THEN Total ELSE 0 END), 2) AS Wed,
ROUND(SUM(CASE WHEN dow = 4 THEN Total ELSE 0 END), 2) AS Thu,
ROUND(SUM(CASE WHEN dow = 5 THEN Total ELSE 0 END), 2) AS Fri,
ROUND(SUM(CASE WHEN dow = 6 THEN Total ELSE 0 END), 2) AS Sat,
ROUND(SUM(Total), 2) AS TotalRevenue,
ROUND(SUM(CASE WHEN dow IN (0, 6) THEN Total ELSE 0 END) * 100.0 / NULLIF(SUM(Total), 0), 2) AS WeekendShare
FROM per_invoice
GROUP BY BillingCountry
HAVING SUM(Total) >= 25
ORDER BY WeekendShare DESC, TotalRevenue DESC;Real code patterns candidates submit that fail the grading suite.
SELECT a.Name, COUNT(t.TrackId) FROM Artist a JOIN Album al ON a.ArtistId = al.ArtistId JOIN Track t ON al.AlbumId = t.AlbumId GROUP BY a.Name;
Three recurring syntax and semantic traps relevant to this problem domain.
Joining a fact table with child lines multiplies fact table rows, distorting sums and counts.
SELECT c.id, SUM(i.total) FROM customer c JOIN invoice i ON c.id = i.customer_id JOIN invoice_line il ON i.id = il.invoice_id -- ❌ Inflated SUM
SELECT c.id, SUM(i.total) FROM customer c JOIN invoice i ON c.id = i.customer_id GROUP BY c.id; -- ✅ Avoids line multiplication
Using COUNT(*) when duplicate rows exist due to joins counts duplicate records.
SELECT artist_id, COUNT(album_id) ... -- ❌ Counts duplicate occurrences
SELECT artist_id, COUNT(DISTINCT album_id) ... -- ✅ Distinct unique entities
In SQL, dividing integers like 5 / 10 results in 0. Cast at least one operand to FLOAT or NUMERIC.
SELECT solved_count / total_count AS rate ... -- ❌ Returns 0
SELECT CAST(solved_count AS FLOAT) / total_count AS rate ... -- ✅ Returns 0.5
Launch our in-browser coding environment. Run queries, view execution plans, and get instant comparative diff grading with no setup.