Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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...
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;
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;
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
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;
T2:
Load
Name,
age,
SUM(Score)
Resident Temp
Group By Name,age;
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;
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).
Thanks guys... Problem Solved