From the course: SQL Hands-On Practice: Solve Business Problems

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Solution: Timestamp differences with LEAD()

Solution: Timestamp differences with LEAD() - SQL Tutorial

From the course: SQL Hands-On Practice: Solve Business Problems

Solution: Timestamp differences with LEAD()

- [Instructor] Now that you've had a chance to work on this timestamp problem on your own, let's work on it together. Here's how I would approach it. Let's start with pulling all of the columns in the payment status log table, and filter for subscription ID 38844. Typically, you don't want to select star too often in SQL because it's better for optimization to only pull the specific columns you need. But since we're investigating statuses for a client, we're going to want to pull everything so we have more data to look into. We're going to start with a select star, and we're pulling this data from the payment status log table, and we're filtering for a certain subscription ID. So we're going to need the WHERE clause, and we're filtering for subscription ID 38844. And remember to put this in single quotes because the query's not going to work without it since our subscription IDs are text data type. Finally, we're…

Contents