Hi there,
I am hoping you can help me with a little puzzle I have here. I have two tables:
1. Transaction Table
Order Date, Customer, Amount
========================================
01/01/2003 BILL 10.00
02/01/2003 BILL 20.00
03/01/2003 BILL 30.00
2. Discount Table
Customer, Effective Date, Discount
==========================================
BILL 01/01/2003 10%
BILL 02/01/2003 20%
BILL 03/01/2003 50%
I want to be able to look up the discount that applies for an order using the effective date.
Eg, have the query return something like this:
Customer, Order Date, Amount, Discount
==========================================================
BILL 01/01/2003 10.00 10%
BILL 02/01/2003 20.00 20%
BILL 03/01/2003 30.00 50%
I have tried the following query - but I keep getting duplicated rows as soon as I add the discount column to the first query:
select t.[order date],
t.amount,
d.discount
from transactions t, discount d
where t.customer = 'BILL'
and [order date] >= ( SELECT Max(d.[effective date])
from discount d
where d.[effective date] <= t.[order date]
)
Any help would be appreciated.
Regards,
Paul.