Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Concat values from one field

Hi,

I'm facing a problem with concat few values from one field.

EX: I have two column called State,Value and those values are like...

State,Value

A,10

B,5

C,12

D,8

I want

State,Value

A/B,15

C/D,20

Can any one please tell me how to get this done.

Thanks in Advance.

Regards,

Arjun

10 Replies
sunny_talwar

What is the logic behind combining 1st 2 together and next 2 together? Is there another dimension based on which you want to combine them?

sunny_talwar

May be like this:

Table:

LOAD * INLINE [

Dim, State Value

1, A, 10

1, B, 5

2, C, 12

2, D, 8

];

FinalTable:

NoConcatenate

LOAD Dim,

          Concat(State, '/') as State,

          Sum(Value) as Value

Reisdent Table

Group By Dim;

Drop Table Table;

Not applicable
Author

Hi Sunny,

There is no logic behind doing this, need to combine few dimension values.

I'm not sure how to do this.

Kushal_Chawda

you should have data like this, then only you will be able to use the concat

Data:

LOAD * inline [

ID,State,Value

1,A,10

1,B,5

2,C,12

2,D,8 ];

New:

noconcatenate

LOAD ID,

          Concat(distinct State,'/') as State,

          sum(Value) as Value

resident Data

group by ID;

drop table Data;

sunny_talwar

Need some basis to know what will be combined into groups, right? How else will you do it in your scenario?

sunny_talwar

Drop Table Data you mean

Kushal_Chawda

Yes, bhavnao ko samjo

sunny_talwar

samjh gaya

Anil_Babu_Samineni

Kushal, I have one question.. What is the difference between your code and Sunny Code. Could you please elaborate that. Because, Sunny code is fine for that Issue....

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful