Jesse Downing Jesse Downing - 1 year ago 65
SQL Question

Count of distinct groups that have a value of > 0 in any of its records for a given column

The two columns:

A) company name. There can be multiple records for a company: 1 record per company per month.

B) Sales. For a given company for a given month, sales is a value 0 or greater.

What I want my query to return:

A count of all the distinct companies that had a sales of > 0 for one or more months

Thanks in advance for your help!

Answer Source

Something similar to:

select count(distinct companyid)
from salestable
where sales > 0

Simply count the number of distinct companyid's who have a sales > 0.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download