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
| When | Account | Debit | Credit |
|---|---|---|---|
| The bill arrives | Smoothie Bar Supplies (expense) | 300.00 | |
| Accounts Payable | 300.00 | ||
| We pay the bill | Accounts Payable | 300.00 | |
| Cash at Bank | 300.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_id | order_date | ordered_by | cups | cost_rm |
|---|---|---|---|---|
| 1 | 2026-08-03 | orangelo | 200 | 60.00 |
| 2 | 2026-08-04 | grapenzo | 1500 | 450.00 |
| 3 | 2026-08-05 | pineapena | 150 | 45.00 |
| 4 | 2026-08-06 | cherrita | 100 | 30.00 |
| 5 | 2026-08-07 | grapenzo | 1800 | 540.00 |
| 6 | 2026-08-10 | orangelo | 250 | 75.00 |
| 7 | 2026-08-11 | kiwilo | 120 | 36.00 |
| 8 | 2026-08-12 | grapenzo | 2000 | 600.00 |
| 9 | 2026-08-13 | strawberrina | 180 | 54.00 |
| 10 | 2026-08-14 | pineapena | 200 | 60.00 |
| 11 | 2026-08-17 | grapenzo | 1600 | 480.00 |
| 12 | 2026-08-18 | cherrita | 90 | 27.00 |
| 13 | 2026-08-19 | orangelo | 220 | 66.00 |
| 14 | 2026-08-20 | bananito | 300 | 90.00 |
| 15 | 2026-08-21 | grapenzo | 1900 | 570.00 |
| 16 | 2026-08-24 | kiwilo | 110 | 33.00 |
| 17 | 2026-08-25 | strawberrina | 160 | 48.00 |
| 18 | 2026-08-26 | pineapena | 210 | 63.00 |
| 19 | 2026-08-27 | grapenzo | 2100 | 630.00 |
| 20 | 2026-08-28 | orangelo | 240 | 72.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?