I have db table like this:
id | user | service | pay_date | status
---+------+---------+--------------+------------
1 | john | 1 | 2014-08-20 | 1
2 | john | 3 | 2014-07-24 | 0
I am trying to build query which return all users who are not payed service 1 or service 3 between 2 dates and haven`t active services (status = 0 for service 1 and service 2). The problem is that query return service 3, but this is not correct because service 1 is active.
SELECT *
FROM services
WHERE date > 2014-07-01
AND date < 2014-07-30
AND service = 1 OR service = 3
My solution is to check if service 3 is active when i`am checking service 1. Something like that...
SELECT *
FROM services
WHERE date > 2014-07-01
AND date < 2014-07-30
AND ((service = 1 AND "SERVICE 3 IS NOT ACTIVE") OR service = 3)
but i cant check if "SERVICE 3 IS NOT ACTIVE" for current user
status = 0 where service = 3
at the place of"SERVICE 3 IS NOT ACTIVE"
– Himanshu Aug 21 '14 at 12:33