Exercises
SQL, Python, JavaScript exercises
82 checked exercises across 3 languages. SQL queries are compared with expected result sets on the sample database; Python and JavaScript programs run against multiple test inputs. Filter by topic, difficulty or progress. Your work stays in this browser.
- Look at the whole product catalogueEasy
The sales team wants to see everything we sell. Return every column of every row in the Products table.
SQLFoundationsNot started
- Just the names and pricesEasy
For a price list, return only the name and unit_price of every product — nothing else.
SQLFoundationsNot started
- Find the expensive productsEasy
Finance wants a list of products that cost more than 400. Return all columns for those products only.
SQLFoundationsNot started
- Who earns the most?Easy
Return the first_name, last_name and salary of every employee, with the highest earner first and the lowest earner last.
SQLFoundationsNot started
- The three priciest itemsEasy
Return the name and unit_price of just the three most expensive products, most expensive first.
SQLFoundationsNot started
- Which countries do we sell to?Easy
Marketing wants a de-duplicated list of the countries our customers are based in. Return each country exactly once, in a single column named country.
SQLFoundationsNot started
- Active engineers onlyEasy
HR needs the first_name and last_name of employees who are in department 10 and are currently active (active = 1). Both conditions must hold.
SQLFoundationsNot started
- Our best-tier customersEasy
Return the company and tier of every customer whose tier is either Gold or Platinum.
SQLFoundationsNot started
- Companies beginning with AMedium
Return the company name of every customer whose company name starts with the letter A.
SQLFoundationsNot started
- Who reports to nobody?Medium
Department heads have no manager, so their manager_id is empty. Return the first_name and last_name of every employee with no manager.
SQLFoundationsNot started
- How many customers do we have?Easy
Return a single row with a single column named total_customers holding the number of rows in the Customers table.
SQLGrouping & JoinsNot started
- Average salary, roundedEasy
Return the average employee salary rounded to the nearest whole number, in one column named avg_salary.
SQLGrouping & JoinsNot started
- Cheapest and dearestEasy
In one row, return the lowest unit_price as min_price and the highest as max_price from the Products table.
SQLGrouping & JoinsNot started
- Revenue actually shippedMedium
Cancelled and pending orders should not count as revenue. Return the sum of order_total for orders with status 'Shipped', in one column named shipped_revenue.
SQLGrouping & JoinsNot started
- Headcount per departmentMedium
Return each dept_id alongside the number of employees in it, with the count in a column named headcount.
SQLGrouping & JoinsNot started
- Biggest departments firstMedium
Return dept_id and headcount as before, but sort so the department with the most employees comes first.
SQLGrouping & JoinsNot started
- Only the multi-person departmentsMedium
Return dept_id and headcount for departments that contain more than two employees.
SQLGrouping & JoinsNot started
- Put a name to the departmentMedium
Employees only store a dept_id. Return each employee's first_name and last_name next to their dept_name by joining to the Departments table.
SQLGrouping & JoinsNot started
- Every department, even the quiet onesHard
Return every dept_name together with how many employees it has, named headcount. Departments with no employees at all must still appear, showing a count of 0.
SQLGrouping & JoinsNot started
- Label each order by sizeHard
Return order_id, order_total, and a column named size_band that reads 'Large' when order_total is 8000 or more, 'Medium' when it is at least 3000 but under 8000, and 'Small' otherwise.
SQLGrouping & JoinsNot started
- Better paid than averageMedium
Return the first_name, last_name and salary of every employee earning more than the company-wide average salary.
SQLAdvanced QueriesNot started
- Customers with a shipped orderMedium
Every customer has ordered something, but not every order ships. Return the company name of each customer who has had at least one order reach 'Shipped' status.
SQLAdvanced QueriesNot started
- Customers still waitingMedium
Now the exact opposite: return the company name of each customer who has never had an order ship — everything they ordered is still pending or was cancelled.
SQLAdvanced QueriesNot started
- Name the managerHard
Return each employee's first_name alongside their manager's first_name in a column named manager_name. Employees with no manager should be left out.
SQLAdvanced QueriesNot started
- One combined contact listMedium
Build a single two-column list of everyone we deal with. Return each employee's first_name and each customer's contact under a shared column named person_name, plus a column named source containing 'Employee' or 'Customer' as appropriate.
SQLAdvanced QueriesNot started
- Revenue by product categoryHard
Return each product category alongside the total order_total it has generated from shipped orders only, in a column named category_revenue, highest revenue first.
SQLAdvanced QueriesNot started
- Who is closing the deals?Hard
Return the first_name and last_name of each employee together with how many orders they handled, in a column named orders_handled, counting shipped orders only, and listing the busiest employee first. Only include employees who handled at least one shipped order.
SQLAdvanced QueriesNot started
- Big spendersHard
Return company and the total spend as total_spent for every customer whose combined order_total across all their orders exceeds 10000, largest spender first.
SQLAdvanced QueriesNot started
- Label the price bandsEasy
Marketing wants each product labelled. Return name, unit_price, and a column called price_label that says premium for products costing 500 or more and standard for everything else.
SQLExpressions & ReportsNot started
- Support levels by tierEasy
Support triages customers by tier. Return company, tier, and support_level: Platinum customers get 'Top priority', Gold customers get 'Standard support', and everyone else gets 'Self-serve'.
SQLExpressions & ReportsNot started
- One-row status reportMedium
Management wants the order pipeline on a single row: three columns named shipped, pending and cancelled, each counting the orders with that status.
SQLExpressions & ReportsNot started
- Revenue won and lostHard
For each employee who has handled orders, return first_name, shipped_revenue (total order_total of their Shipped orders) and cancelled_revenue (total of their Cancelled orders), highest shipped_revenue first.
SQLExpressions & ReportsNot started
- Mailing labelsEasy
HR needs mailing labels: a single column full_name (first name, a space, last name) plus email, for every employee, alphabetical by full_name.
SQLExpressions & ReportsNot started
- Case-insensitive searchEasy
A colleague types 'an' into the customer search box and expects every company whose name contains those two letters, whether they are stored in upper or lower case - so 'Andes' counts as well as 'Meridian'. Return company.
SQLExpressions & ReportsNot started
- Strip the domainMedium
For the Engineering department (dept_id 10), return each employee's email and a column mailbox holding the email with '@example.com' removed.
SQLExpressions & ReportsNot started
- The longest product namesMedium
The catalogue layout breaks on long names. Return name and name_length for every product whose name is 18 characters or longer.
SQLExpressions & ReportsNot started
- Who reports to whomMedium
List every employee's first_name alongside reports_to - their manager's first name, or the text 'No manager' for employees at the top of the tree.
SQLExpressions & ReportsNot started
- Orders by monthMedium
How does order volume spread across the year? Return order_month (the month number from order_date) and orders (how many orders that month), earliest month first.
SQLExpressions & ReportsNot started
- Big orders, with namesMedium
Define a CTE called big_orders that selects orders with order_total above 3000, then return order_id, company and order_total for those orders.
SQLExpressions & ReportsNot started
- Well-paid departmentsHard
Using a CTE that computes each department's average salary, return dept_name and avg_salary for the departments whose average exceeds 100000.
SQLExpressions & ReportsNot started
- Two CTEs, one reportHard
Build a per-salesperson report using two CTEs: one counting each employee's Shipped orders, one totalling each employee's revenue across all orders. Return first_name, shipped_orders and revenue, highest revenue first.
SQLExpressions & ReportsNot started
- Category revenue reportHard
The quarterly report needs revenue by product category, ignoring cancelled orders: return category, orders (count) and revenue (sum of order_total), biggest revenue first.
SQLExpressions & ReportsNot started
Python
All Python exercises →- Choose a delivery windowEasy
Classify a parcel into a delivery window with clear Python if, elif and else conditions.
PythonConditionsNot started
- Dispatch message initialsEasy
Create uppercase initials from a multi-word dispatch message using Python string operations.
PythonStringsNot started
- Market basket totalEasy
Read item prices and quantities, then print the basket total with two decimal places using Python arithmetic.
PythonBasicsNot started
- Parcel cost functionEasy
Write and call a Python function that calculates a parcel charge from weight and distance bands.
PythonFunctionsNot started
- Unique route stopsEasy
Remove repeated bus stops while preserving first-seen order with Python lists and membership checks.
PythonListsNot started
- After-sales shortfallsMedium
Compute post-sale stock shortfalls for products and report only items that fall below their minimum.
PythonDictionariesNot started
- First repeated checkpointMedium
Detect the first checkpoint visited twice in a route while preserving the route's travel order.
PythonSetsNot started
- Inventory movement tallyMedium
Aggregate stock movements by product and print a sorted Python dictionary report.
PythonDictionariesNot started
- Longest reading streakMedium
Find the longest run of reading days from a compact activity string using a Python loop.
PythonLoopsNot started
- Merge visitor countsMedium
Merge two counters of venue visits while preserving totals for visitors seen in either source.
PythonDictionariesNot started
- Safe reading averageMedium
Parse sensor tokens safely in Python and average only valid numeric readings using exception handling.
PythonExceptionsNot started
- Shared route stopsMedium
Find the stops shared by two bus routes without losing the first route's order.
PythonSetsNot started
- Shipping code normalizerMedium
Normalize mixed-case shipping codes, remove formatting hyphens and emit distinct codes alphabetically.
PythonStringsNot started
- Stock movement ledgerMedium
Aggregate signed warehouse movements per SKU and produce a deterministic inventory change report.
PythonDictionariesNot started
- Valid order totalMedium
Validate quantity and integer-cent price rows before summing order value and counting rejected rows.
PythonExceptionsNot started
- Valid sensor averageMedium
Average only valid bounded sensor readings and report how many malformed readings were rejected.
PythonExceptionsNot started
- Word frequency reportMedium
Count repeated words with a Python dictionary and print a deterministic alphabetical frequency report.
PythonDictionariesNot started
- Busiest sales daysHard
Find the earliest fixed-width sales window with the greatest total using a sliding sum.
PythonListsNot started
- Restock priority reportHard
Calculate stock shortfalls and rank urgent restocks with deterministic tie-breaking.
PythonDictionariesNot started
- Shelf pair targetHard
Find the lexicographically smallest pair of distinct shelf weights that matches an exact target.
PythonListsNot started
JavaScript
All JavaScript exercises →- Cafe bill totalEasy
Read prices and quantities, then print a JavaScript cafe bill total with exactly two decimal places.
JavaScriptBasicsNot started
- Cold-room alertEasy
Classify a sensor reading with JavaScript if, else if and exact boundary handling.
JavaScriptConditionsNot started
- Deduplicate article tagsEasy
Remove repeated tags while preserving first-seen order using JavaScript arrays and includes.
JavaScriptArraysNot started
- Headline to URL slugEasy
Normalise a simple headline into a lowercase hyphenated URL slug with JavaScript string methods.
JavaScriptStringsNot started
- Shipping fee functionEasy
Write and call a JavaScript function that calculates shipping from weight and distance.
JavaScriptFunctionsNot started
- Dispatch code normalizerMedium
Normalize and deduplicate dispatch codes with mixed case and formatting hyphens.
JavaScriptStringsNot started
- First repeated ticketMedium
Find the first ticket ID whose second appearance occurs earliest in a scan log.
JavaScriptArraysNot started
- Longest open runMedium
Scan a status string and find its longest consecutive open period with a JavaScript loop.
JavaScriptLoopsNot started
- Merge shift hoursMedium
Merge two shift-hour exports by employee without losing repeated records or zero-hour entries.
JavaScriptObjectsNot started
- Priority ticket orderMedium
Sort support tickets by descending priority with an alphabetical ID tie-break.
JavaScriptArraysNot started
- Ticket code countsMedium
Count repeated support codes with a JavaScript object and print a sorted frequency report.
JavaScriptObjectsNot started
- Validated score averageMedium
Calculate an average from whole-number scores while accounting for malformed and out-of-range tokens.
JavaScriptError HandlingNot started
- Warehouse movement tallyMedium
Aggregate warehouse movements by item and print sorted totals with a JavaScript object.
JavaScriptObjectsNot started
- Best revenue windowHard
Find the earliest maximum-revenue stretch of fixed length using an O(N) sliding window.
JavaScriptArraysNot started
- Invoice discount in centsHard
Calculate integer-cent invoice discounts with a cap and explicit threshold boundaries.
JavaScriptFunctionsNot started
- Pallet pair under limitHard
Choose the heaviest pair of distinct pallets under a weight limit with deterministic tie-breaking.
JavaScriptArraysNot started
- Peak staffing windowHard
Find the earliest minute with maximum overlapping shifts using a sweep over start and end events.
JavaScriptArraysNot started
- Refund ledger auditHard
Reconcile partial refunds against orders while rejecting unknown and over-refund entries.
JavaScriptObjectsNot started
- Seat inventory eventsHard
Apply signed seat changes per venue while rejecting events that would breach capacity or go negative.
JavaScriptObjectsNot started
- Unique parcel registerHard
Accept well-formed unique parcel records while rejecting duplicate IDs and invalid quantities.
JavaScriptError HandlingNot started