1

I have a table named orders that contains order_id, order_date and order_shipped. I need to be able to query the difference in days between ordered and shipped for the whole table but only display the order_id's that have 15 or more days between them and I have no idea how to build that query.

1 Answer 1

1

Basically you want to select the ids where the date difference is at least 15.

SELECT order_id
FROM orders
WHERE datediff(order_shipped, order_date) >= 15

This could be slow if there are many orders, because the function result cannot be indexed and needs to be calculated every time.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm an idiot. I had originally worked out this query for myself but thought I must have been doing something wrong since it wasn't returning values. turns out, there aren't any order_id's that fit the criteria. Thank you for the input. it is working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.