thomasrawley
Programmer
- Aug 21, 2008
- 3
I am having trouble wrapping my head around this one.
Here is the table of information I am working with.
ORDERS
Store# Order# Date
01 01 8/14
01 01 6/28
01 02 8/13
02 01 8/12
02 02 8/14
03 01 8/13
03 01 8/1
03 02 8/16
So let me explain the table first. It holds order history information (which is why you see multiple rows for the same store/order combination with different dates). I can easily filter out the statuses that I don't want and when I do that, this is the info I am left with. This represents completed orders.
The goal here is the following output.
Store# Count(Orders that completed for the first time)
01 1
02 2
03 1
I only care about orders that completed FOR THE FIRST TIME in a week boundary (so if I choose last week, I only care about orders that completed between 8/11 and 8/17 FOR THE FIRST TIME).
For example, since order 1 in store 1 completed before the week I care about, I do not want to include it.
How would I write a SQL statement to do this? I can of course have an intermediate step but would prefer to have it all in one SQL statement.
I will be querying a DB2 database if that matters.
Any help would be appreciated.
Thanks,
Thomas
Here is the table of information I am working with.
ORDERS
Store# Order# Date
01 01 8/14
01 01 6/28
01 02 8/13
02 01 8/12
02 02 8/14
03 01 8/13
03 01 8/1
03 02 8/16
So let me explain the table first. It holds order history information (which is why you see multiple rows for the same store/order combination with different dates). I can easily filter out the statuses that I don't want and when I do that, this is the info I am left with. This represents completed orders.
The goal here is the following output.
Store# Count(Orders that completed for the first time)
01 1
02 2
03 1
I only care about orders that completed FOR THE FIRST TIME in a week boundary (so if I choose last week, I only care about orders that completed between 8/11 and 8/17 FOR THE FIRST TIME).
For example, since order 1 in store 1 completed before the week I care about, I do not want to include it.
How would I write a SQL statement to do this? I can of course have an intermediate step but would prefer to have it all in one SQL statement.
I will be querying a DB2 database if that matters.
Any help would be appreciated.
Thanks,
Thomas