mac100
mac100

Reputation: 137

How to count number of unique records of a field in progress openedge 4gl?

I have customer table with a field age . How can I count how many distinct ages are there ?

Upvotes: 1

Views: 3275

Answers (2)

Ajinkya
Ajinkya

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

Jensd
Jensd

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

Related Questions