Peter, this is my take on the data query.
I like to split a complex query into serialized queries, each of which addressing a specific need.
This as opposed to a nested query notation.
​
Filtering the planets with one or more moons can be done as follows:
(Note that this is rather trivial as we only need to remove the planets Mercury and Venus)
In[]:=
planets=ExampleData[{"Dataset","Planets"}];
In[]:=
Select[Length@Keys@#Moons>=1&]@planets
Out[]=
Mass
Radius
Moons
Mass
Radius
Earth
5.9721986×
24
10
kg
6367.4447km
Moon
7.3459×
22
10
kg
1737.5km
Mars
6.41693×
23
10
kg
3386.km
Phobos
1.072×
16
10
kg
11.1km
Deimos
1.5×
15
10
kg
6.2km
Jupiter
1.89813×
27
10
kg
69173.km
Metis
1.×
17
10
kg
21.5km
Adrastea
7.×
15
10
kg
8.2km
Amalthea
2.07×
18
10
kg
83.45km
63 total ›
Saturn
5.68319×
26
10
kg
57316.km
Tarqeq
—
3.5km
Pan
4.9×
15
10
kg
12.8km
Daphnis
—
3.9km
61 total ›
Uranus
8.68103×
25
10
kg
25266.km
Cordelia
4.5×
16
10
kg
20.1km
Ophelia
5.4×
16
10
kg
21.4km
Bianca
9.3×
16
10
kg
25.7km
27 total ›
Neptune
1.02410×
26
10
kg
24553.km
Naiad
1.9×
17
10
kg
33.km
Thalassa
3.7×
17
10
kg
41.km
Despina
2.1×
18
10
kg
75.km
13 total ›
Next, we need to remove any moons with missing masses or we get into trouble with the density calculation later:
Query[All,<|#,"Moons"->Select[!MissingQ@#Mass&]@#Moons|>&]@planets
Out[]=
Mass
Radius
Moons
Mass
Radius
Earth
5.9721986×
24
10
kg
6367.4447km
Moon
7.3459×
22
10
kg
1737.5km
Mars
6.41693×
23
10
kg
3386.km
Phobos
1.072×
16
10
kg
11.1km
Deimos
1.5×
15
10
kg
6.2km
Jupiter
1.89813×
27
10
kg
69173.km
Metis
1.×
17
10
kg
21.5km
Adrastea
7.×
15
10
kg
8.2km
Amalthea
2.07×
18
10
kg
83.45km
38 total ›
Saturn
5.68319×
26
10
kg
57316.km
Pan
4.9×
15
10
kg
12.8km
Atlas
2.1×
15
10
kg
10.km
Prometheus
1.867×
17
10
kg
46.8km
33 total ›
Uranus
8.68103×
25
10
kg
25266.km
Cordelia
4.5×
16
10
kg
20.1km
Ophelia
5.4×
16
10
kg
21.4km
Bianca
9.3×
16
10
kg
25.7km
21 total ›
Neptune
1.02410×
26
10
kg
24553.km
Naiad
1.9×
17
10
kg
33.km
Thalassa
3.7×
17
10
kg
41.km
Despina
2.1×
18
10
kg
75.km
8 total ›
Let’s create a constant of the Earth’s moon density:
In[]:=
moondensity=Query["Earth","Moons",1,"Mass"]@planets
4
3
PiQuery["Earth","Moons",1,"Radius"]@planets^3;
​
Now let’s create a dataset with the moons density relative to the Earth’s Moon with all of the above filters applied:
In[]:=
QueryAll,<|#,"Moons"->QueryAll,<|"Density"->#Mass
4
3
Pi#Radius^3moondensity|>&@#Moons|>&@Query[All,<|#,"Moons"->Select[!MissingQ@#Mass&]@#Moons|>&]@Select[Length@Keys@#Moons>=1&]@planets
Out[]=
Mass
Radius
Moons
Density
Earth
5.9721986×
24
10
kg
6367.4447km
Moon
1.0
Mars
6.41693×
23
10
kg
3386.km
Phobos
0.56
Deimos
0.44
Jupiter
1.89813×
27
10
kg
69173.km
Metis
0.9
Adrastea
1.0
Amalthea
0.254
38 total ›
Saturn
5.68319×
26
10
kg
57316.km
Pan
0.17
Atlas
0.15
Prometheus
0.13
33 total ›
Uranus
8.68103×
25
10
kg
25266.km
Cordelia
0.4
Ophelia
0.39
Bianca
0.39
21 total ›
Neptune
1.02410×
26
10
kg
24553.km
Naiad
0.39
Thalassa
0.39
Despina
0.36
8 total ›
Note: I changed the dataset by adding the column density in place of the mass and radius columns. This simplified my query and removes redundant information.
BTW: If you want to sort the moons by density, this is how you can do it:
In[]:=
Query[All,<|#,"Moons"->ReverseSortBy[#Density&]@#Moons|>&]@%
Out[]=
Mass
Radius
Moons
Density
Earth
5.9721986×
24
10
kg
6367.4447km
Moon
1.0
Mars
6.41693×
23
10
kg
3386.km
Phobos
0.56
Deimos
0.44
Jupiter
1.89813×
27
10
kg
69173.km
Sponde
1.
Pasithee
1.
Orthosie
1.
38 total ›
Saturn
5.68319×
26
10
kg
57316.km
Narvi
0.57
Titan
0.56226
Phoebe
0.4885
33 total ›
Uranus
8.68103×
25
10
kg
25266.km
Titania
0.5127
Ariel
0.498
Oberon
0.4874
21 total ›
Neptune
1.02410×
26
10
kg
24553.km
Triton
0.61624
Nereid
0.449
Galatea
0.39
8 total ›

Putting it all together

To wrap it all up, let’s create a comprehensive overview of all planets with moons with more than 0.55 of the Earth’s Moon density.
At last, I will create a separate dataset of the corresponding planets radii.
Note: if the selection of the moons density yields in none, it will create an empty row in the Moons section. Therefore I have to remove the planet with no moon results with Select[Keys@#Moons!={}&]
In[]:=
Query[All,KeyDrop["Mass"]]@Select[Keys@#Moons!={}&]@Query[All,<|#,"Moons"->Select[#Density>0.55&]@#Moons|>&]@QueryAll,<|#,"Moons"->QueryAll,<|"Density"->#Mass
4
3
Pi#Radius^3moondensity|>&@#Moons|>&@Query[All,<|#,"Moons"->Select[!MissingQ@#Mass&]@#Moons|>&]@Select[Length@Keys@#Moons>=1&]@planets​​Query[All,{"Radius"}]@%
Out[]=
Radius
Moons
Density
Earth
6367.4447km
Moon
1.0
Mars
3386.km
Phobos
0.56
Jupiter
69173.km
Metis
0.9
36 total ›
Saturn
57316.km
Titan
0.56226
Neptune
24553.km
Triton
0.61624