I've been trying to generate a table using MAX(somedate). My goal is to pull one row of data from (storeitems) that is JOINed to another table that has the prices. However, the (price) table has more than one listing for the price. I want the most current price using the (effectivedate) field.
Here's my statement so far:
SELECT its.storeid,OnHandQty,(OnHandQty*rv.price) rtvalue,rv.price,its.itemid,(mcl.descr)subcat,(its.descr)itemdescr,mcl.parentclass
FROM StoreItem its
JOIN (SELECT itemid,price,MAX(effectivedttm) as currdate FROM EffectiveStoreItemRetailValue GROUP BY itemid,price)rv on its.itemid=rv.itemid
JOIN MdseClass mcl on its.classid=mcl.classid
WHERE its.storeid= 50
AND OnHandQty <> 0
GROUP BY its.storeid,OnHandQty,rtvalue,its.itemid,subcat,itemdescr,mcl.parentclass,rv.price
ORDER BY mcl.parentclass;
I'm doing some other things in this statement, however, my main concern is why the MAX(somedate) is not working. I have a feeling it has to do with how I'm joining the tables..
Thanks in advance folks!
Tim
Here's my statement so far:
SELECT its.storeid,OnHandQty,(OnHandQty*rv.price) rtvalue,rv.price,its.itemid,(mcl.descr)subcat,(its.descr)itemdescr,mcl.parentclass
FROM StoreItem its
JOIN (SELECT itemid,price,MAX(effectivedttm) as currdate FROM EffectiveStoreItemRetailValue GROUP BY itemid,price)rv on its.itemid=rv.itemid
JOIN MdseClass mcl on its.classid=mcl.classid
WHERE its.storeid= 50
AND OnHandQty <> 0
GROUP BY its.storeid,OnHandQty,rtvalue,its.itemid,subcat,itemdescr,mcl.parentclass,rv.price
ORDER BY mcl.parentclass;
I'm doing some other things in this statement, however, my main concern is why the MAX(somedate) is not working. I have a feeling it has to do with how I'm joining the tables..
Thanks in advance folks!
Tim