SQL Streaks Problem: Identify Continuous Task Results

🚨 90% of SQL learners get this wrong — can you solve it? While exploring SQL problems by Ankit Bansal, I came across a deceptively simple question that really tests your understanding of data patterns, not just syntax. 👉 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐜𝐞𝐧𝐚𝐫𝐢𝐨: You’re given a table that stores daily task results (success / fail). Your challenge is to: ➡️ Identify continuous streaks of the same state ➡️ Merge them into a single row with start date and end date Sounds easy… until you try it 😄 👉 𝐓𝐚𝐛𝐥𝐞 𝐒𝐞𝐭𝐮𝐩: create table tasks ( date_value date, state varchar(10) ); insert into tasks values ('2019-01-01','success'), ('2019-01-02','success'), ('2019-01-03','success'), ('2019-01-04','fail'), ('2019-01-05','fail'), ('2019-01-06','success'); 👉 𝐄𝐱𝐩𝐞𝐜𝐭𝐞𝐝 𝐎𝐮𝐭𝐩𝐮𝐭: start_date | end_date | state -----------|------------|-------- 2019-01-01 | 2019-01-03 | success 2019-01-04 | 2019-01-05 | fail 2019-01-06 | 2019-01-06 | success 🧠 𝐓𝐡𝐢𝐬 𝐩𝐫𝐨𝐛𝐥𝐞𝐦 𝐢𝐬 𝐚 𝐜𝐥𝐚𝐬𝐬𝐢𝐜 𝐞𝐱𝐚𝐦𝐩𝐥𝐞 𝐨𝐟: Pattern recognition in data Real-world analytics scenarios (streaks, sessions, trends) Thinking beyond basic GROUP BY 💬 Drop your approach in the comments — curious to see different ways to solve this! And if you’ve solved it before, how did you think about it? Shoutout to Ankit Bansal for consistently sharing high-quality SQL problems 🙌 #SQL #DataAnalytics #DataEngineering #InterviewPrep #LearnSQL

  • text

To view or add a comment, sign in

Explore content categories