SQL proof of work
A small PostgreSQL database for a commercial property deal pipeline, built to show working SQL rather than describe it. Ten queries, from a plain SELECT to window functions. Every table on this page is the real output of the query printed directly above it, captured from a live run.
The data is invented. Brokers, agencies, properties
and values are synthetic seed data written for this project. No real company,
person, client or transaction appears anywhere in it. Reproduce the whole thing
with one command: ./run.sh
Top open deals by value: the live pipeline, biggest first.
SELECT subject, status, deal_value_zar FROM deals WHERE status IN ('New', 'In review', 'Qualified') AND deal_value_zar > 0 ORDER BY deal_value_zar DESC;
| subject | status | deal_value_zar |
|---|---|---|
| Century City mixed use block | New | R96,000,000 |
| Kempton Park land rezoning | In review | R55,000,000 |
| Montague Gardens warehouse disposal | In review | R42,000,000 |
| Northgate anchor tenant sale | In review | R41,200,000 |
| Riverside Heights bulk sale | In review | R33,800,000 |
| Sandton Exchange floor 9 | New | R31,000,000 |
| Paarden Eiland depot mandate | Qualified | R27,500,000 |
| Harbour sheds portfolio | Qualified | R23,400,000 |
| Foreshore sublease opportunity | New | R18,500,000 |
| Montague Park expansion erf | New | R12,800,000 |
| Harbour sheds tenant buyout | New | R9,800,000 |
| Northgate parking lease | Qualified | R4,600,000 |
12 rows
Review queue: flagged deals with their reasons, newest first.
SELECT subject, review_reason, deal_value_zar, received_at FROM deals WHERE needs_review = true ORDER BY received_at DESC;
| subject | review_reason | deal_value_zar | received_at |
|---|---|---|---|
| Foreshore naming rights query | No deal value stated in mail | R0 | 2026-07-17 13:27:00 |
| Riverside Heights bulk sale | Deal value above the review threshold | R33,800,000 | 2026-07-12 15:08:00 |
| Kempton Park land rezoning | Rezoning risk not yet verified | R55,000,000 | 2026-07-09 08:55:00 |
| Northgate anchor tenant sale | Deal value above the review threshold | R41,200,000 | 2026-07-03 11:02:00 |
4 rows
Deals with the sector and province of the property they concern.
SELECT d.subject, p.sector, p.province, d.deal_value_zar FROM deals d JOIN properties p ON p.property_id = d.property_id ORDER BY d.received_at;
| subject | sector | province | deal_value_zar |
|---|---|---|---|
| Montague Gardens warehouse disposal | Industrial | Western Cape | R42,000,000 |
| Foreshore sublease opportunity | Office | Western Cape | R18,500,000 |
| Northgate anchor tenant sale | Retail | Gauteng | R41,200,000 |
| Paarden Eiland depot mandate | Industrial | Western Cape | R27,500,000 |
| Sandton Exchange floor 9 | Office | Gauteng | R31,000,000 |
| Ridge Plaza food court rights | Retail | KwaZulu-Natal | R8,200,000 |
| Kempton Park land rezoning | Land | Gauteng | R55,000,000 |
| Century City mixed use block | Mixed use | Western Cape | R96,000,000 |
| Harbour sheds portfolio | Industrial | Eastern Cape | R23,400,000 |
| Riverside Heights bulk sale | Residential | Gauteng | R33,800,000 |
| Montague Park expansion erf | Industrial | Western Cape | R12,800,000 |
| Foreshore naming rights query | Office | Western Cape | R0 |
| Northgate parking lease | Retail | Gauteng | R4,600,000 |
| Exchange Building auction notice | Office | Gauteng | R0 |
| Harbour sheds tenant buyout | Industrial | Eastern Cape | R9,800,000 |
15 rows
Full deal sheet: who brought which deal on which property.
SELECT d.message_id, b.full_name AS broker, b.agency, p.common_name AS property, d.deal_value_zar, d.status FROM deals d JOIN brokers b ON b.broker_id = d.broker_id JOIN properties p ON p.property_id = d.property_id ORDER BY d.message_id;
| message_id | broker | agency | property | deal_value_zar | status |
|---|---|---|---|---|---|
| MSG-0001 | Thandi Mokoena | Atlantic Properties | Montague Park Warehouse | R42,000,000 | In review |
| MSG-0002 | Nolan Fourie | Cape Commercial Brokers | Foreshore Offices | R18,500,000 | New |
| MSG-0003 | Sarah Naidoo | Metro Realty Group | Northgate Centre | R41,200,000 | In review |
| MSG-0004 | James Botha | Southpoint Estates | Paarden Eiland Depot | R27,500,000 | Qualified |
| MSG-0005 | Lerato Dlamini | Urban Yield Capital | Exchange Building | R31,000,000 | New |
| MSG-0006 | Sarah Naidoo | Metro Realty Group | Ridge Plaza | R8,200,000 | Declined |
| MSG-0007 | Nolan Fourie | Cape Commercial Brokers | Kempton Land Parcel | R55,000,000 | In review |
| MSG-0008 | Thandi Mokoena | Atlantic Properties | Century City Annex | R96,000,000 | New |
| MSG-0009 | James Botha | Southpoint Estates | Harbour Sheds | R23,400,000 | Qualified |
| MSG-0010 | Lerato Dlamini | Urban Yield Capital | Riverside Heights | R33,800,000 | In review |
| MSG-0011 | Thandi Mokoena | Atlantic Properties | Montague Park Warehouse | R12,800,000 | New |
| MSG-0012 | Nolan Fourie | Cape Commercial Brokers | Foreshore Offices | R0 | New |
| MSG-0013 | Sarah Naidoo | Metro Realty Group | Northgate Centre | R4,600,000 | Qualified |
| MSG-0014 | Lerato Dlamini | Urban Yield Capital | Exchange Building | R0 | Closed |
| MSG-0015 | James Botha | Southpoint Estates | Harbour Sheds | R9,800,000 | New |
15 rows
Broker coverage: every broker, including those with zero deals.
SELECT b.full_name, b.agency, b.is_active, count(d.deal_id) AS deal_count, coalesce(sum(d.deal_value_zar), 0) AS total_value_zar FROM brokers b LEFT JOIN deals d ON d.broker_id = b.broker_id GROUP BY b.broker_id, b.full_name, b.agency, b.is_active ORDER BY deal_count DESC, b.full_name;
| full_name | agency | is_active | deal_count | total_value_zar |
|---|---|---|---|---|
| James Botha | Southpoint Estates | Yes | 3 | R60,700,000 |
| Lerato Dlamini | Urban Yield Capital | Yes | 3 | R64,800,000 |
| Nolan Fourie | Cape Commercial Brokers | Yes | 3 | R73,500,000 |
| Sarah Naidoo | Metro Realty Group | Yes | 3 | R54,000,000 |
| Thandi Mokoena | Atlantic Properties | Yes | 3 | R150,800,000 |
| Michael Abrahams | Peninsula Property Co | No | 0 | R0 |
6 rows
Open pipeline value by property sector.
SELECT p.sector, count(*) AS open_deals, sum(d.deal_value_zar) AS pipeline_zar, round(avg(d.deal_value_zar), 0) AS avg_deal_zar FROM deals d JOIN properties p ON p.property_id = d.property_id WHERE d.status IN ('New', 'In review', 'Qualified') GROUP BY p.sector ORDER BY pipeline_zar DESC;
| sector | open_deals | pipeline_zar | avg_deal_zar |
|---|---|---|---|
| Industrial | 5 | R115,500,000 | R23,100,000 |
| Mixed use | 1 | R96,000,000 | R96,000,000 |
| Land | 1 | R55,000,000 | R55,000,000 |
| Office | 3 | R49,500,000 | R16,500,000 |
| Retail | 2 | R45,800,000 | R22,900,000 |
| Residential | 1 | R33,800,000 | R33,800,000 |
6 rows
Agencies whose open pipeline exceeds R30M.
SELECT b.agency, count(*) AS open_deals, sum(d.deal_value_zar) AS pipeline_zar FROM deals d JOIN brokers b ON b.broker_id = d.broker_id WHERE d.status IN ('New', 'In review', 'Qualified') GROUP BY b.agency HAVING sum(d.deal_value_zar) > 30000000 ORDER BY pipeline_zar DESC;
| agency | open_deals | pipeline_zar |
|---|---|---|
| Atlantic Properties | 3 | R150,800,000 |
| Cape Commercial Brokers | 3 | R73,500,000 |
| Urban Yield Capital | 2 | R64,800,000 |
| Southpoint Estates | 3 | R60,700,000 |
| Metro Realty Group | 2 | R45,800,000 |
5 rows
Weekly deal flow: deals received and value per week. Same pattern with date_trunc('month', ...) gives monthly deal flow once the data spans more than one month.
SELECT date_trunc('week', received_at)::date AS week_starting, count(*) AS deals_received, sum(deal_value_zar) AS value_received_zar FROM deals GROUP BY week_starting ORDER BY week_starting;
| week_starting | deals_received | value_received_zar |
|---|---|---|
| 2026-06-29 | 4 | R129,200,000 |
| 2026-07-06 | 6 | R247,400,000 |
| 2026-07-13 | 3 | R17,400,000 |
| 2026-07-20 | 2 | R9,800,000 |
4 rows
Vacancy-style view: properties with no open deal against them, i.e. stock on the books that nothing live is happening on.
SELECT p.common_name, p.sector, p.province FROM properties p WHERE NOT EXISTS ( SELECT 1 FROM deals d WHERE d.property_id = p.property_id AND d.status IN ('New', 'In review', 'Qualified') ) ORDER BY p.sector, p.common_name;
| common_name | sector | province |
|---|---|---|
| Ridge Plaza | Retail | KwaZulu-Natal |
1 row
Broker leaderboard: rank by open pipeline and share of the whole book.
SELECT rank() OVER (ORDER BY sum(d.deal_value_zar) DESC) AS rank, b.full_name, b.agency, sum(d.deal_value_zar) AS pipeline_zar, round(100.0 * sum(d.deal_value_zar) / sum(sum(d.deal_value_zar)) OVER (), 1) AS pct_of_book FROM deals d JOIN brokers b ON b.broker_id = d.broker_id WHERE d.status IN ('New', 'In review', 'Qualified') GROUP BY b.broker_id, b.full_name, b.agency ORDER BY rank;
| rank | full_name | agency | pipeline_zar | pct_of_book |
|---|---|---|---|---|
| 1 | Thandi Mokoena | Atlantic Properties | R150,800,000 | 38.1 |
| 2 | Nolan Fourie | Cape Commercial Brokers | R73,500,000 | 18.6 |
| 3 | Lerato Dlamini | Urban Yield Capital | R64,800,000 | 16.4 |
| 4 | James Botha | Southpoint Estates | R60,700,000 | 15.3 |
| 5 | Sarah Naidoo | Metro Realty Group | R45,800,000 | 11.6 |
5 rows