Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have the below table
KEY flag Day
1A 1 0
1A 0 1
1A 1 2
2A 0 0
2A 1 1
3A 0 0
3A 0 1
i need to generate another table with the KEY and a counter which indicates the number of 1's between 0 to n Day
KEY Counter
1A 2
2A 1
3A 0
Please help me with the logic
Try this:
Counter:
Load KEY, sum(flag) as Counter Resident table Group by KEY;
- Marcus
Try this:
Counter:
Load KEY, sum(flag) as Counter Resident table Group by KEY;
- Marcus
tab3:
load * inline [
KEY, flag, Day
1A , 1 , 0
1A , 0 , 1
1A , 1 , 2
2A , 0 , 0
2A , 1 , 1
3A , 0 , 0
3A , 0 , 1
];
tab5:
load
KEY,
count(flag) as count
resident tab3
group by KEY;
Thanks Marcus,
Suppose if there are more number of days and how can we find if Flag is 1 in once in 3 days?
Hoping for a solution
I don't know how the flag is created. Maybe you could change these logic or you could load these table additionally with a where-clause:
Load Key, flag as 1_flag Resident result where flag = 1;
It will be depend in which situations you want what to do.
- Marcus