Jump to content

Clear items created or not change in the last 90 days


deuxk

Recommended Posts

Hi,

I'd get to do a join query with 3 (sometimes 2).

Here is the structure of my 3 tables in question:
items> id, cat, subcategory, created
status> itemId, level
Modify> id, itemId, date, type

Here's my query so far:

SELECT
	i.id,
	i.userId
FROM
	items i
LEFT OUTER JOIN statut s ON i.id = s.itemId
WHERE
	CASE WHEN (
		SELECT m.date
		FROM modification m
		WHERE m.itemId = i.id
		ORDER BY m.date DESC LIMIT 1
	) IS NULL THEN
	i.created
	END > DATE_SUB(NOW(), INTERVAL 90 DAY)
AND s. LEVEL = 1

I would like to get a look at what the last change add and see if it has been over 90 days. In case no change was made compared with the creation date of the item. He that can strongly that there are several changes to a single item so it should really checked with the last added in case there.

Thank you for your help!

The only bit I understood was the title "items created or not change in the last 90 days"

 

Try

SELECT
      i.id
    , i.userId
FROM items i
    LEFT JOIN modify m
        ON m.itemId = i.id
        AND m.date > CURDATE() - INTERVAL 90 DAY
WHERE m.date IS NULL
    OR i.created > CURDATE() - INTERVAL 90 DAY

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.