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

Group By function with sum

Hi guys,

I would like to use the group by function with aggregate function as sum.

lets say the input is

Name       age           class                Score

a               6                1                       4

a               6                1                       3

a               6                1                       5

The desired output is

Name        age         class                  Score

a                6               1                       12

The script I tried:

Load Name,

          age,

          class,

           Sum(Score) as Score

from samplefile.csv

group by Name;

But the execution fails with error "Invalid expression"

Kindly Help Me out...

1 Solution

Accepted Solutions
its_anandrjs

Then not use class field in the load script do like

Load   Name,

          age,

          //class,

          Sum(Score) as Score

from samplefile.csv

group by Name,age;

View solution in original post

7 Replies
MK_QSL
MVP
MVP

Load Name,

          age,

          class,

           Sum(Score) as Score

from samplefile.csv

group by Name,age,class;

Update:

=====================================

Temp:

Load * Inline

[

  Name,       age,           class,                Score

a,               6 ,               1,                       4

a,               6 ,               1,                       3

a,               6 ,               1,                       5

];

T2:

Load

  Name,

  age,

  class,

  SUM(Score)

Resident Temp

Group By Name,age,class;

Drop Table Temp;

Not applicable
Author

Hi thank you for the prompt answer. But in case i dont want the class field in output, do i still need to group by all the fields preceeding the aggregate function

its_anandrjs

You have to group by all the fields in the table see the script and load according to that

Load   Name,

          age,

          class,

          Sum(Score) as Score

from samplefile.csv

group by Name,age,class;

MK_QSL
MVP
MVP

T2:

Load

  Name,

  age,

  SUM(Score)

Resident Temp

Group By Name,age;

its_anandrjs

Then not use class field in the load script do like

Load   Name,

          age,

          //class,

          Sum(Score) as Score

from samplefile.csv

group by Name,age;

Anonymous
Not applicable
Author

Hi Paromita,

All the fields mentioned inside the load statement along with sum function should(compulsory)  also be mentioned in the group by clause.

But All fields which are mentioned in group by clause need not be used in load statement.(only if require u mention the field in the load statement else not required).

Not applicable
Author

Thanks guys... Problem Solved