The other day I needed to find the total distinct count of a column as well as the distinct count of that column when a specific criteria had been met. In order to do this you can do the following:

    count(distinct column) as full,
    count(distinct case when column2 = 1 then column end) as partial
from a;

This is mostly here so I’ll remember the next time I need this. :-)

Like this post? Don't forget to follow us on Twitter and Facebook for updates.