How many times does this part appear?

basic:
part, subpart, count
foreign key to
part, desc table

select subpartlist, countlist by part from partsubpart 

part, desc, superpartlist, countofthisinsuper, subpartlist, countofsubinthis

subpart, superpart, countofsubpartinsuper

superpart, subpart

If I can fit only so many parts in my warehouse and subparts
should come before superparts, which ones should come first?

How many times does this part appear altogether?
Have to avoid double-counting.
How do we do that?
Look up part and then go up the superpaprtlist
collecting counts as you go.
It's recursive:

find:{[p]
sum: 0;



select 
