CASE IDP-2026-117
← back to the board
open folder

Query Cheat Sheet

The only SQL you need

1 · Filter and sort

SELECT column1, column2
FROM some_table
WHERE column1 = 'value'
ORDER BY column2 DESC;

2 · Add up per group

SELECT column1, COUNT(*), SUM(amount)
FROM some_table
GROUP BY column1;

3 · Combine two tables

SELECT a.*, b.name
FROM table_a AS a
JOIN table_b AS b ON a.shared_id = b.shared_id;

Tips: text goes in 'single quotes'. Dates look like '2026-03-19'. WHERE description LIKE '%fog%' finds text containing "fog".

Accounting in five minutes

The accounting equation

Assets = Liabilities + Equity

  • Assets: what the company owns (cash, equipment, prepaid insurance).
  • Liabilities: what it owes (Accounts Payable: bills not yet paid).
  • Equity: what belongs to the owners.

During the year, revenue adds to equity and expenses take it away, so:

Assets = Liabilities + Equity + Revenue − Expenses

Debits and credits keep it balanced

Every journal entry has debits and credits, and they always add up to the same amount. Assets and expenses grow with debits; liabilities, equity and revenue grow with credits.

A normal purchase takes two entries

WhenAccountDebitCredit
The bill arrivesSmoothie Bar Supplies (expense)300.00
Accounts Payable300.00
We pay the billAccounts Payable300.00
Cash at Bank300.00

Expense or asset?

  • An expense is used up: smoothie cups, props for one episode, villa rent.
  • An asset is something the company keeps and uses over time: cameras, buildings, land.
  • Prepaid items are assets for a short while: you pay a year of insurance up front, then expense it month by month.

Act 0 · Practice case: who keeps over-ordering the smoothie cups?

We solve this one together on the projector. Table smoothie_cup_orders:

order_idorder_dateordered_bycupscost_rm
12026-08-03orangelo20060.00
22026-08-04grapenzo1500450.00
32026-08-05pineapena15045.00
42026-08-06cherrita10030.00
52026-08-07grapenzo1800540.00
62026-08-10orangelo25075.00
72026-08-11kiwilo12036.00
82026-08-12grapenzo2000600.00
92026-08-13strawberrina18054.00
102026-08-14pineapena20060.00
112026-08-17grapenzo1600480.00
122026-08-18cherrita9027.00
132026-08-19orangelo22066.00
142026-08-20bananito30090.00
152026-08-21grapenzo1900570.00
162026-08-24kiwilo11033.00
172026-08-25strawberrina16048.00
182026-08-26pineapena21063.00
192026-08-27grapenzo2100630.00
202026-08-28orangelo24072.00

Step 1 · Look at everything, sorted

SELECT *
FROM smoothie_cup_orders
ORDER BY cups DESC;

ORDER BY sorts the rows. DESC puts the biggest first.

Step 2 · Narrow it down

SELECT order_date, ordered_by, cups
FROM smoothie_cup_orders
WHERE cups > 1000;

WHERE keeps only the rows that match a condition.

Step 3 · Add it up per person

SELECT ordered_by, COUNT(*) AS orders, SUM(cost_rm) AS total_rm
FROM smoothie_cup_orders
GROUP BY ordered_by
ORDER BY total_rm DESC;

GROUP BY makes one row per person. SUM adds up each person's orders.

Then the accounting question: smoothie cups are booked to 5200 Smoothie Bar Supplies. Is that an expense or an asset, and why?