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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.