Using result of aggregate from top level group inside lower level group
问题 I have 2 tables A{int id,int grp}, B{int aid,int cat}. Table B contains list of categories that record of table A belongs to, so B.aid is Foreign Key that references A.id. A.id is unique primary key of table A. B.cat contains category number from 1 to 5, A.grp contains numbers from 1 to 1000. Table A has 3 million of records, table B - about 5 million. For each group A.grp I need to calculate % of records in A that contain B.cat out of number of records within group A.grp. So if A:[{1,1},{2,1