There is a table of users with fields date_created, contract_type .
I need to withdraw in the request of all users who have expired contract.
You need to do a check on the field contract_type , which can have two values: M2M - 30 days, Annual - year.
How to add conditions for contract types to this request and check if the contract has expired?
SELECT u.id, u.dateCreated, DATE(NOW()) as date_now, c.name FROM users u JOIN contract_type c ON u.contract_type = c.id WHERE u.contract_type is not null Own attempt of the decision:
It seems that he himself thought up something, only he swears at CONCAT, tell me where the error is. Thank you, of course, for the right answer, I just wanted to try to solve the problem myself too.
SELECT u.id, u.email, u.dateCreated, DATE(NOW()) as date_now, c.name, CASE c.name WHEN "M2M" THEN 'MONTH' ELSE "YEAR" END as type_value FROM users u JOIN contract_type c ON u.contract_type = c.id HAVING date_now > u.dateCreated + INTERVAL CONCAT("1", type_value)