Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Dear All,
Please find below data. I need to Pick the max date and associated time for the given ID in script.
ID | Date | Time | Name |
101 | 01-02-2017 | 11:04:25 | ABC |
101 | 04-05-2017 | 18:12:14 | PQR |
101 | 07-08-2017 | 09:45:45 | XYZ |
101 | 07-08-2017 | 09:45:50 | LMN |
The result should be :
ID | Date | Time | Name |
101 | 07-08-2017 | 09:45:50 | LMN |
Regards
Sumeet
Data:
Load
ID,
Date(Date#(Date,'DD-MM-YYYY')) as Date,
Time,
Name
Inline
[
ID, Date, Time, Name
101, 01-02-2017, 11:04:25, ABC
101, 04-05-2017, 18:12:14, PQR
101, 07-08-2017, 09:45:45, XYZ
101, 07-08-2017, 09:45:50, LMN
];
Left Join (Data)
Load ID, Date(Max(Date)) as MaxDate Resident Data Group By ID;
Left Join (Data)
Load ID, Time(Max(Time)) as MaxTime Resident Data Where Date = MaxDate Group By ID;
NoConcatenate
Final:
Load ID, Date, Time, Name Resident Data
Where Date = MaxDate and Time = MaxTime;
Drop Table Data;
Data:
Load
ID,
Date(Date#(Date,'DD-MM-YYYY')) as Date,
Time,
Name
Inline
[
ID, Date, Time, Name
101, 01-02-2017, 11:04:25, ABC
101, 04-05-2017, 18:12:14, PQR
101, 07-08-2017, 09:45:45, XYZ
101, 07-08-2017, 09:45:50, LMN
];
Left Join (Data)
Load ID, Date(Max(Date)) as MaxDate Resident Data Group By ID;
Left Join (Data)
Load ID, Time(Max(Time)) as MaxTime Resident Data Where Date = MaxDate Group By ID;
NoConcatenate
Final:
Load ID, Date, Time, Name Resident Data
Where Date = MaxDate and Time = MaxTime;
Drop Table Data;
Try using firstsortedvalue(), like:
Yeah that's the easiest way.. But Sumeet wants to achieve at script level.. Otherwise this is easy to do at front end.
For script try like:
t1:
Load * Inline [
ID, Date, Time, Name
101, 01-02-2017, 11:04:25, ABC
101, 04-05-2017, 18:12:14, PQR
101, 07-08-2017, 09:45:45, XYZ
101, 07-08-2017, 09:45:50, LMN];
NoConcatenate
t2:
load
ID,
FirstSortedValue(Date, -(Date+Time)) as Date,
FirstSortedValue(Time, -(Date+Time)) as Time,
FirstSortedValue(Name, -(Date+Time)) as Name
Resident t1 Group by ID;
Drop Table t1;
Excellent.. This is better solution. But issue in using FirstSortedValue is ...
say we have below one more line.
101, 07-08-2017, 09:45:50, XXX
In this case, we will not get result.
If we use Distinct then will get one line one...
But we need here two lines...
So I avoided FirstSortedValue..
......
But we need here two lines...
Lets wait to know OP's expectation.
Thanks Manish, That works perfectly for me.
Regards
Sumeet
Hi Tresco,
Thanks for your reply but i wanted to achieve it at the script level.
Regards
Sumeet
If you got your answer, then kindly close the thread by selecting correct/helpful answer.