NGB
NGB

Reputation: 41

datediff() query for multiple dates

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.

Upvotes: 1

Views: 190

Answers (1)

Arjan
Arjan

Reputation: 9874

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.

Upvotes: 1

Related Questions