Your question is Query Walkthrough. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
A KPMG engagement team is testing for premature revenue recognition: contracts where the client's ledger recorded revenue before the contract's service period had even started, which is a classic audit red flag. You are given the schema below and asked to write the query yourself, not shown someone else's.
CREATE TABLE contracts (
contract_id INT PRIMARY KEY,
client_id INT,
service_start_date DATE,
service_end_date DATE,
contract_value NUMERIC(14,2)
);
CREATE TABLE revenue_entries (
entry_id BIGINT PRIMARY KEY,
contract_id INT REFERENCES contracts(contract_id),
recognized_date DATE,
recognized_amount NUMERIC(14,2)
);
-- a contract can have zero, one, or many revenue_entries rows
-- recognized_date and service_start_date can both be NULL for a small number of
-- legacy contracts migrated from a prior system
Write a query that flags every revenue_entries row recognized before its contract's service_start_date, showing contract_id, client_id, recognized_date, service_start_date, and the amount recognized early. Then describe, in your own words, how you would validate that your query is correct before handing the result to the engagement partner: what edge cases would you test, and how would you check each one by hand.