David Pet
David Pet

Reputation: 107

Mysql Count Distinct with Where clause

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!

Upvotes: 0

Views: 114

Answers (1)

Sergiu Costas
Sergiu Costas

Reputation: 560

Modify this zone_id !=1 with zone_id <> 1 or zone_id NOT LIKE '1'

Upvotes: 1

Related Questions