Reputation: 137
I have customer table with a field age . How can I count how many distinct ages are there ?
Upvotes: 1
Views: 3275
Reputation: 1
It will be somewhat on these lines: Replace City with age and employee with customer in the following code.
def var i as int no-undo.
for each employee break by city:
if first-of (city) and last-of(city)
then do:
i = i + 1.
end.
end.
display "The count of unique records" i with frame a.
Upvotes: 0
Reputation: 8011
You can do it in ABL using a FOR-loop and BREAK BY and a counter. There are also built in aggregate functions (ACCUM) in the ABL but they are rarely seen in the wild...
DEFINE VARIABLE i AS INTEGER NO-UNDO.
FOR EACH record NO-LOCK BREAK BY record.age:
IF LAST-OF(record.age) THEN DO:
i = i + 1.
END.
END.
MESSAGE "There are " i " unique ages" VIEW-AS ALERT-BOX.
Or by the crippled built in SQL:
SELECT COUNT(DISTINCT age) FROM record.
Upvotes: 4