You can try the following:
select count(distinct tag) as tag_count, count(distinct (case when entryId > 0 then tag end)) as positive_tag_count from your_table_name;
The first count(distinct...) is simple. The second one looks a bit complicated, actually the same as the first, except that you use the case...when clause. In the case...when clause, you only filter positive values. Zeros or negative values will be null and will not be counted.
It should be noted that this can be done by reading the table once. When it seems to you that you need to read the same table twice or more, this can be done by reading once, in most cases. As a result, it will complete the task much faster with fewer I / O operations.
ntalbs Dec 27 2018-12-12T00: 00Z
source share