Hi I have the following query to get all of the pricing out of my system. I need to have all of these selections grouped and then I need to select the 2nd newest date to get the prior day pricing. The problem is that the prior day pricing isn't Today - 1 day. It may be Today - 5 days for example for a certain stock_id. I am doing this quest through microsoft query in excel so row_number() cannot be used.
The query would output the following:
MS_CODE LOCATION_CODE MFG_CODE GROUP_CODE STOCK_ID EFFECTIVE_DATE PRICE
COKE 12 23 HTG 23 01/12/2018 1.00
COKE 12 23 HTG 23 01/11/2018 0.99
COKE 12 23 HTG 23 01/10/2018 1.05
PEPSI 12 23 HTG 23 01/12/2018 1.10
PEPSI 12 23 HTG 23 01/11/2018 1.00
PEPSI 12 23 HTG 23 01/10/2018 0.60
What I need to output would be:
MS_CODE LOCATION_CODE MFG_CODE GROUP_CODE STOCK_ID EFFECTIVE_DATE PRICE
COKE 12 23 HTG 23 01/11/2018 0.99
PEPSI 12 23 HTG 23 01/11/2018 1.00
My Current Query is:
SELECT
dbo.PRICE_BOOK.ms_code,
dbo.PRICE_BOOK.location_code,
dbo.PRICE_BOOK.mfg_code,
dbo.PRICE_BOOK.group_code,
dbo.PRICE_BOOK.stock_id,
dbo.PRICE_BOOK.effective_date,
dbo.PRICE_BOOK.price
FROM dbo.PRICE_BOOK
Thanks in advance.