Hi Team,
I have below data
ID | Desc |
1234 | A |
1234 | B |
1234 | C |
5678 | T |
5678 | J |
Need Output as below (I need desc based on First occurrence of ID):
ID | Desc |
1234 | A |
5678 | T |
You could use EXISTS(). It is quite effective. See example below, it will give you the desired result.
DATA:
LOAD * INLINE [
ID Desc
1234 A
1234 B
1234 C
5678 T
5678 J]
(delimiter is ' ')
WHERE NOT Exists(ID)
;
Data:
LOAD ID,DESC
FROM YourQVD;
// Sort your data on next load to get the correct values
Final:
LOAD *
where Flag=1;
LOAD *,
if(rowno()=1 or ID<>previous(ID),1,0) as Flag
resident Data
order by ID,Desc;
drop table Data;
You could use EXISTS(). It is quite effective. See example below, it will give you the desired result.
DATA:
LOAD * INLINE [
ID Desc
1234 A
1234 B
1234 C
5678 T
5678 J]
(delimiter is ' ')
WHERE NOT Exists(ID)
;
Data:
LOAD ID,DESC
FROM YourQVD;
// Sort your data on next load to get the correct values
Final:
LOAD *
where Flag=1;
LOAD *,
if(rowno()=1 or ID<>previous(ID),1,0) as Flag
resident Data
order by ID,Desc;
drop table Data;