October 22, 2024
Chicago 12, Melborne City, USA
SQL

BigQuery average on parent and child


I’m trying to get average count of child items.
I have a table like below

parent_id| child_id | Type 
1        | 11         | A
1        | 11         | B
1        | 12         | A
1        | 12         | B
1        | 13         | A
2        | 14         | A
2        | 15         | B
2        | 15         | A

In the output I want to know for a given parent_id, what is the average count of A and average count of B.
I achieved that using groupby.
But wanted to check if in the same query I can get the average count of A for child_id also?
In short getting average count of Type per child and add a column which will tell me average count of Type per parent_id also.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video