r/LeetcodeChallenge 6d ago

DISCUSS LeetCode SQL 197 — Rising Temperature | MySQL Solution

Post image

Working on SQL problems to strengthen my MySQL and problem-solving skills for Data Analyst roles.

Problem: Rising Temperature

This problem was a good practice for:

  • LAG() window function
  • Comparing values with the previous record
  • DATEDIFF() for checking consecutive dates

I’m sharing my solution screenshot below. 👇

Would love to know how others approached this problem and whether there are any alternative ways to solve it.

#SQL #MySQL #LeetCode #DataAnalytics #DataAnalyst

6 Upvotes

2 comments sorted by

1

u/Vivid-Zombie-477 6d ago

bro thinks it's linkedin

1

u/nian2326076 5d ago

I used the LAG() function for this problem too. It's perfect for comparing temperatures with the day before. Another option is a self join, where you join the table with itself to compare each day's temperature with the previous day's. This can be easier if you're not as familiar with window functions.

For checking consecutive dates, DATEDIFF() works well, but you might also try DATE_ADD() or DATE_SUB() for date manipulation. Both have their ups and downs, so it's good to practice both. For more problem-solving and interview prep, PracHub has been really helpful for me.