Not sure I understand fully what you're trying to accomplish. However, it seems like one thing you need to know is the list of contact record ID's linked to a given membership (including the contacts who inherit the membership from another contact).
The owner_membership_id in civicrm_membership links inherited memberships to the "primary member". For example, if I wanted to find out all the contacts who have inherited membership from contact 5 ...
SELECT contact_id
FROM `civicrm_membership`
WHERE owner_membership_id
IN ( SELECT id FROM civicrm_membership WHERE contact_id =5
)
You could then get a count on the civicrm_participant records for the event you are interested in, where contact_id is in the list returned above.
Not sure this is on track for what you're trying to do. Hopefully it's a start. Else, I guess pinging one of us on IRC is your best bet.