简体   繁体   中英

Get records which were not updated the day before

I need to get a list of items which were not updated the day before.

I currently have...

 SELECT     dbo.aboProducts.asin, dbo.aboProducts.sku
 FROM       dbo.aboProducts INNER JOIN
            dbo.LowestPrices ON dbo.aboProducts.asin = dbo.LowestPrices.productAsin
 WHERE     (dbo.LowestPrices.priceDate <= DATEADD(day, - 1, GETDATE()))

This however returns nothing. If i change the <= to >= i get results from the last 24 hours. I just need to return any items which were NOT updated, and leave the ones that were updated alone.

That looks fine, assuming every Product has at least one entry in LowestPrices. Do you actually have any items that weren't updated?

try this:

SELECT     aboProducts.asin, aboProducts.sku
FROM       dbo.aboProducts 
where aboProducts.asin 
not in(
     select aboProducts.asin 
     FROM       dbo.aboProducts 
     INNER JOIN
                dbo.LowestPrices 
     ON aboProducts.asin = LowestPrices.productAsin
     WHERE     (LowestPrices.priceDate >= DATEADD(day, - 1, GETDATE()))
 )

Try this:

 SELECT     dbo.aboProducts.asin, dbo.aboProducts.sku
 FROM       dbo.aboProducts INNER JOIN
            dbo.LowestPrices ON dbo.aboProducts.asin = dbo.LowestPrices.productAsin
 WHERE     (dbo.LowestPrices.priceDate != DATEADD(day, - 1, GETDATE()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM