AWS Certified Data Engineer Associate DEA-C01 Practice Question
An ecommerce company stores clickstream events in an Amazon Redshift table named events with columns (session_id VARCHAR, event_ts TIMESTAMP, page VARCHAR). To build a downstream table that contains only the earliest page visited in each session, the engineer wants to write a single SQL statement that avoids self-joins or subqueries. Which query pattern meets these requirements while scanning the table only once?
SELECT DISTINCT session_id, FIRST_VALUE(page) OVER (PARTITION BY session_id ORDER BY event_ts) AS page FROM events;
SELECT e.session_id, e.page FROM events e INNER JOIN (SELECT session_id, MIN(event_ts) AS first_ts FROM events GROUP BY session_id) s ON e.session_id = s.session_id AND e.event_ts = s.first_ts;
SELECT session_id, page FROM events ORDER BY event_ts LIMIT 1;
SELECT session_id, page FROM events QUALIFY ROW_NUMBER() OVER (PARTITION BY session_id ORDER BY event_ts) = 1;
Amazon Redshift supports the QUALIFY clause, which filters the results of window functions after the window is computed. Using ROW_NUMBER with PARTITION BY session_id and ordering by event_ts assigns 1 to the first row in each session. QUALIFY then keeps only those rows, producing the required result in a single pass of the source table. The GROUP BY-MIN-JOIN pattern scans the table twice, the DISTINCT with FIRST_VALUE still requires an outer query to remove duplicates, and ORDER BY … LIMIT 1 returns only one row for the entire data set, not one per session.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the QUALIFY clause in Amazon Redshift?
Open an interactive chat with Bash
How does PARTITION BY work in window functions?
Open an interactive chat with Bash
Why is ROW_NUMBER used in this query instead of RANK or DENSE_RANK?
Open an interactive chat with Bash
What is the QUALIFY clause in SQL?
Open an interactive chat with Bash
What is the ROW_NUMBER() function in SQL?
Open an interactive chat with Bash
Why is the MIN-GROUP BY-JOIN approach less efficient?
Open an interactive chat with Bash
AWS Certified Data Engineer Associate DEA-C01
Data Ingestion and Transformation
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .