
Answer-first summary for fast verification
Answer: ```sql SELECT customer_id, bill_date, amount FROM table_changes('bills', 0) WHERE _change_type = 'insert';
The correct answer is option E. When Change Data Feed is enabled for a delta table, the `table_changes()` function can be used to access change data logs. To retrieve the initial bill details for all customers, you should query the `table_changes('bills', 0)` with a filter on `_change_type = 'insert'`, as this captures the first insertion of each customer's bill. This approach ensures you only get the original bill details without subsequent updates or deletions.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
A broadband company uses a delta table named bills with Change Data Feed enabled to store the latest bills of all customers. The table is updated whenever a new bill is generated, with only the bill_date and amount columns being updated for existing customers. If a customer leaves the company, their bill details are deleted from the bills table. Which query should be used to retrieve the list of all customers along with the details of their first-ever bill?
A
SELECT customer_id,
bill_date,
amount
FROM table_changes('bills', 0)
WHERE _change_type = 'INSERT';
SELECT customer_id,
bill_date,
amount
FROM table_changes('bills', 0)
WHERE _change_type = 'INSERT';
B
SELECT customer_id, bill_date, amount
FROM table_changes('bills', 0)
WHERE _change_type IN ('insert', 'delete');
SELECT customer_id, bill_date, amount
FROM table_changes('bills', 0)
WHERE _change_type IN ('insert', 'delete');
C
SELECT customer_id, bill_date, amount
FROM bills
WHERE _change_type = 'INSERT';
SELECT customer_id, bill_date, amount
FROM bills
WHERE _change_type = 'INSERT';
D
SELECT customer_id, bill_date, amount
FROM table_changes('bills', 0)
WHERE _change_type IN ('insert', 'update_preimage');
SELECT customer_id, bill_date, amount
FROM table_changes('bills', 0)
WHERE _change_type IN ('insert', 'update_preimage');
E
SELECT customer_id, bill_date, amount
FROM table_changes('bills', 0)
WHERE _change_type = 'insert';
SELECT customer_id, bill_date, amount
FROM table_changes('bills', 0)
WHERE _change_type = 'insert';