MySQL distinct count -
abc table -
id --- 1 2 3
xyz table -
abc_id | flag -------------- 1 | 0 1 | 1 2 | 0 3 | 0 3 | 0
i need count of distinct abc_id if flag = 1 particular abc_id, id shouldn't counted. in above example, count should 2. there way can accomplish that? sorry if question has been answered before or if it's obvious. in advance ^^
edit: want abc_id = 1 ignored in count because 1 of it's flag = 1. hope it's clear plenty :|
the main issue figuring out meant, i'm pretty sure it's this. :o)
count distinct abc_id
s, excluding ids have @ to the lowest degree 1 row flagged. id 1 excluded, because has flag.
you can solve not in
condition, exclude ids flagged. after that, can count remaining rows, using count(distinct abc_id)
, number of distinct ids.
select count(distinct abc_id) non_flagged_id_count xyz x1 abd_id not in (select x2.abc_id xyz x2 x2.flag = 1)
mysql distinct
No comments:
Post a Comment