I am trying to get a count of Ids using some conditions.
This is my initial Query:
SELECT
COUNT(DISTINCT (id))
FROM
my_table
WHERE
app_id = 1
AND zone_id != 1
AND presence_time_secs > 20
AND initial_timestamp BETWEEN '2017-05-02 00:00:00' AND '2017-05-05 00:00:00'
group by
day(initial_timestamp)
So my problem is that is not getting the zone_id!=1 part.
There are a few values when I do the same query using zone_id=1, but if in the first query i take the zone_id!=1it will return exactly the same values.
What am I doing wrong?
(I have also tried using NOT IN, same results).
Thanks in advance!
zone_id!=1count is as same aszone_id=1count.AND zone_id != 1and see the result. I think you should query all the result without aggregation to confirm if data is correct or not.SELECT ZONE_ID, COUNT(DISTINCT(Id)) AS RC FROM MYTABLE WHERE app_id = 1 /* AND zone_id != 1 */ AND presence_time_secs > 20 AND initial_timestamp BETWEEN '2017-05-02 00:00:00' AND '2017-05-05 00:00:00' group by day(initial_timestamp) , ZONE_ID