Human traffic stadium X stadium built a new stadium, each day many people visit it,…
- User
Human traffic stadium X stadium built a new stadium, each day many people visit it, write a query to display the records which have 3 or more consecutive rows and the amount of people more than 100(inclusive) using cte
- Assistant
Assuming that the table name is "stadium_visitors" and it has the following columns:
- date_visited (DATE): The date when the stadium was visited
- visitors (INT): The number of visitors on that date
The following query can be used to display the records which have 3 or more consecutive rows with the amount of people more than 100 (inclusive) using a Common Table Expression (CTE):
WITH consecutive_visitors AS ( SELECT date_visited, visitors, ROW_NUMBER() OVER (ORDER BY date_visited) AS row_num, ROW_NUMBER() OVER (PARTITION BY visitors > 100 ORDER BY date_visited) AS group_num FROM stadium_visitors ) SELECT date_visited, visitors FROM consecutive_visitors WHERE visitors > 100 AND EXISTS ( SELECT * FROM consecutive_visitors c2 WHERE c2.group_num = consecutive_visitors.group_num AND c2.visitors > 100 AND c2.row_num > consecutive_visitors.row_num ) ORDER BY date_visited;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.