This query is marked as a draft This query has been published by MolecularPilot.

SQL

AخA
 
SELECT u.user_id, u.user_name, MAX(l.log_timestamp) AS last_block_time
FROM user u
JOIN logging l
    ON u.user_id = l.log_user
    AND l.log_type = 'block'           -- Log type for block events
    AND l.log_action = 'block'         -- Specific action is block
    AND l.log_timestamp >= DATE_SUB(NOW(), INTERVAL 2 MONTH) -- Blocks in the last 2 months
LEFT JOIN block b
    ON u.user_id = b.bl_target         -- Join on block table to find current blocks
    AND b.bl_expiry > NOW()            -- Ensure the block hasn't expired yet
WHERE b.bl_target IS NULL              -- Ensure the user is not currently blocked
GROUP BY u.user_id, u.user_name;
By running queries you agree to the Cloud Services Terms of Use and you irrevocably agree to release your SQL under CC0 License.
All SQL code is licensed under CC0 License.

Checking query status...