We have been working on a N1QL. need help in changing it so that we can achieve the requirement

You need to work similar like How to write the following N1ql Query - #2 by vsr1
similar id aggregate all products and enc, status and use case.