Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
i need to get the count of two columns from same table and put it into separate table.
For this i have to write a script so please help me on this.
Thanks in advance
Regards,
Sudha Banakar
Hi
Try like this
MainTable:
Load ProductID, Category, Product From tablename;
Table1:
Load ProductID, Count(Product) As ProductCount Resident MainTable Group by ProductID;
Table2:
Load ProductID, Count(Category) As CategoryCount Resident MainTable Group by ProductID;
Edit:
Forget to give group by
Hi,
If it is to be added to another table then go for join or concat
Else just you want to get it in another table with same data then the one provided by Mayil is best
Hello Sudha,
You can try below, But you should have a Key field to join these counts to rest of the data model and for that you would need to use the Group By Clause.
Maintable:
LOAD * INLINE [
ProductID, Category, IsTraded, IsShipped
123, Iphone, 0, 0
124, samsung, 1, 1
125, Iphone, 1, 0
126, Iphone, 1, 1
127, Iphone, 1, 1
];
CountTable:
LOAD
sum(IsTraded) as TotalTraded,
sum(IsShipped) as TotalShipped
Resident Maintable;
Thanks,
ASINGH