Link to home
Start Free TrialLog in
Avatar of Clif
ClifFlag for United States of America

asked on

Counting Unique Records

I'm using Crystal XI

I have a report that lists jobs per cost center.  Some jobs can show up on different cost centers.  If I count records (how I'm currently doing it), I get more jobs than are actually on the report.

My current query is something like:
SELECT * 
FROM MyView

Open in new window

which returns 150 records.  This is not the number of jobs, since a job might appear in two or more rows with differing cost centers.
What I need is something like
SELECT COUNT(DISTINCT Job_No)
FROM MyView

Open in new window

which will return 85, the actual number of jobs.

These, of course, would be filtered through Crystal's Record Selection Formulae.

Is there a way to count just the unique records based on a single field?
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
Mike McCracken

If you are trying to do it in the SQL try

SELECT DISTINCT Job_No, Count(Job_No) as JobCount FROM MyView

mlmcc
Avatar of Clif

ASKER

DistinctCount was exactly what I was looking for.

Thanks.