Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Can we use group by function for resident table as below. No giving any error. But i am not sure about it. Please suggest whether it is right way or not.
For Exp:
A:
Load *
from etc.xls
B:
load *,
min(Field_name) as minfield
resident A group by Field_names;
drop table A;
You should not use * to selection while using group by.
You can select fields by using Aggregation functions and the fields used in group by clause.
Example:
A:
Load
ID,
PName,
Price,
Unit
From Datasource;
B:
Load
ID,
PName,
Max(Price) AS MPrice,
Max(Unit) AS MUnit
Resident A
Group By ID, PName;
I can use the ID and PName fields directly but not the Price and Unit. To use this fields i should apply some group by or aggregation functions.
of course you can, but be careful with the stars and grouping fields.
Your example a little bit modified without errors.
A:
Load
ID,
Value
Inline
[ID, Value
1, 3
1, 5
1, 7
2, 4
2, 6
2, 8];
B:
LOAD
ID,
Min(Value) as MinValue
Resident
A
Group by ID;
drop table A;
You should not use * to selection while using group by.
You can select fields by using Aggregation functions and the fields used in group by clause.
Example:
A:
Load
ID,
PName,
Price,
Unit
From Datasource;
B:
Load
ID,
PName,
Max(Price) AS MPrice,
Max(Unit) AS MUnit
Resident A
Group By ID, PName;
I can use the ID and PName fields directly but not the Price and Unit. To use this fields i should apply some group by or aggregation functions.