Skip to content

SQL- Iterate through a list of WHERE clause values

I have a table like so:

I want to find the total order_qty where the item_id matches, and the order_date is between two date values. The issue is that each item_id has different dates to check so they cannot be a constant in the where clause.

Although this will not run I was thinking something like this:

Advertisement

Answer

Do you actually want to iterate, or just return matching results?

Sounds like this might be the direction you want to go:

(Although comparing string literals to date fields is not a good idea, use to_date (Oracle) or equivalent function to translate the string literals to dates. The following is an Oracle example:

User contributions licensed under: CC BY-SA
1 People found this is helpful