Summarize mulitpe records into one

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
rdy
Participant
Posts: 38
Joined: Wed Nov 05, 2003 2:40 pm

Summarize mulitpe records into one

Post by rdy »

I have multiple records per individual, based on an individual type. Each one will either be A or I. (Active or inactive.)

I need to boil that down to one record per individual, that follows this business rule:

"If an individual has any active records, they are active."

i.e.

Three records:
John Doe, Type 1, A
John Doe, Type 2, A
John Doe, Type 3, I

One summary record:
John Doe, A

How can I do this with DataStage and SQL? (If I were writing a stored procedure I would step through the three records and keep an "active indicator".)
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Code: Select all

   select name from yourtable
   group by name 
   having sum(case when status = 'A' then 1 else 0 end) > 0
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

How about:
SELECT NAME, MIN(STATUS)
FROM YOURTABLE
GROUP BY NAME

Assuming here that A and I are the only valid values for STATUS and you want to return both Active and Inactive names. A will be returned ahead of I using the MIN function.
Post Reply