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
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.
1 Comment
NGB
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