My SQL Query - Get items that had there prices reduced in the last 30 days

Viewed 27

I have a table that keeps track of inventory price updates.

CREATE TABLE pricechangelog (
    id int,
    SKU varchar(50),
    oldSelling DOUBLE(22,2),
    newSelling DOUBLE(22,2),
    date DATETIME
);

I would like to get the items that had their price reduced overrall in the last 30 days, how would I go about doing that

1 Answers

This could be possible by find the difference of the current timestamp and the date. DATEDIFF() Function, and the newselling value shuould be less than the oldselling

SELECT * 
FROM pricechangelog 
WHERE DATEDIFF(CURRENT_TIMESTAMP, date)<= 30 
AND oldSelling>newSelling;
Related