Dear Dave :
Thank you for this well - crafted example that allowed me to learn new tricks . The following light blue marks are my usual usage in
work .
On the one hand, my colleagues think it is easier to understand, and on the other hand I can modify it to understand .
​
Pred Liu

Planets ExampleData

In[]:=
planets=ExampleData[{"Dataset","Planets"}]

1
Create a separate dataset of all Moons Properties

In[]:=
Join@@Query[Values,"Moons"]@planets;​​
planets[Values/*Apply[Join],"Moons"]

2
Create a Dataset with a list of all moons per planet

In[]:=
Query[All,{"Moons"},Keys]@planets;​​
planets[All,"Moons",Keys]
​​

3
Create a sorted Dataset with the number of moons per planet

In[]:=
ReverseSort@Query[All,{"Moons"},Length]@planets;​​
planets[All,{"Moons"},Length]

4
Create a sorted Dataset with the total moon mass per planet

In[]:=
ReverseSortBy[#Moons&]@Query[All,{"Moons"},Total@*Values,"Mass"]@planets;​​
planets[NumericalSort/*Reverse,{"Moons"},Values/*Total,"Mass"];
​​
planets[All,{"Moons"},Values/*Total,"Mass"][ReverseSort]

5
Select the heaviest moons per planet

In[]:=
Query[All,Query[TakeLargest[#,1]&,"Mass"]@#Moons&]@Select[Keys@#Moons!={}&]@planets;​​
planets[Select[#["Moons"]=!=<||>&],"Moons",MaximalBy[{"Mass"}],"Mass"]
​​
In[]:=
Query[Transpose,Query[TakeLargest[#,1]&,"Mass"]@#Moons&]@Select[Keys@#Moons!={}&]@planets;​​
planets[Select[#["Moons"]=!=<||>&]/*Transpose,"Moons",MaximalBy[{"Mass"}],"Mass"]
In[]:=
Query[All,"Moons",TakeLargestBy[#Mass&,1]]@Select[Keys@#Moons!={}&]@planets;​​
planets[Select[#["Moons"]=!=<||>&],"Moons",MaximalBy[{"Mass"}]]

6
Select all planets with a larger mass than earth’s

In[]:=
Query[Select[#Mass>planets["Earth","Mass"]&],{"Mass"}]@planets;​​
planets[Select[#["Mass"]>planets["Earth","Mass"]&],{"Mass"}]

7
Add a column with the planets’ density

In[]:=
e3=QueryAll,<|"Mass"->#Mass,"Radius"->#Radius,"Density"->N#Mass
4
3
Pi#Radius^3,"Moons"->#Moons|>&@planets;​​
planetsAll,Insert#,"Density"->N#["Mass"]
4
3
Pi#["Radius"]^3,3&

8
Create a new Dataset of the planets’ density relative to earth’s

In[]:=
ReverseSort@Query[All,<|"RelativeDensity"->With[{mass=Query["Earth","Density"]@e3},#Density/mass]|>&]@e3;​​
e3[All,<|"RelativeDensity"->With[{mass=Query["Earth","Density"]@e3},#Density/
mass]|>&][ReverseSortBy["RelativeDensity"]];
​​
e3[NumericalSort/*Reverse,<|"RelativeDensity"->With[{mass=Query["Earth","Density"]@e3},#Density/mass]|>&]

9
Create a Dataset of the planets’ density relative to water’s

In[]:=
Sort@QueryAll,<|"RelativeDensity"->Withmass=UnitConvert
water
CHEMICAL

density
,Times["Kilograms",Power["Kilometers",-3]],#Densitymass|>&@e3;​​
e3NumericalSort,<|"RelativeDensity"->Withmass=UnitConvert
water
CHEMICAL

density
,Times["Kilograms",
Power["Kilometers",-3]],#Densitymass|>&

10
Convert in-place Jupiter’s moons radii measured in earth’s moon units

radii=planets["Earth","Moons","Moon","Radius"];​​MapAt[With[{r=Query["Earth","Moons",1,"Radius"]@planets},#/radii&],{"Jupiter","Moons",All,"Radius"}]@planets;​​​​
planets[MapAt[#/radii&,{"Jupiter","Moons",All,"Radius"}]]

11
Convert-in-place Mars’s Deimos and Jupiter’s Metis mass and radius resp. relative to Earth’s moon

In[]:=
m=planets["Mars","Moons","Deimos","Mass"]/planets["Earth","Moons","Moon","Mass"];​​r=planets["Jupiter","Moons","Metis","Radius"]/planets["Earth","Moons","Moon","Radius"];​​ReplacePart[{{"Mars","Moons","Deimos","Mass"}->m,{"Jupiter","Moons","Metis","Radius"}->r}]@planets;​​
planets[ReplacePart[{{"Mars","Moons","Deimos","Mass"}->m,{"Jupiter","Moons","Metis","Radius"}->r}]]

12
Convert in-place all planets’ and moons’ radii relative to Earth’s moon

radiimoon=planets["Earth","Moons",1,"Radius"];​​MapAt[With[{r=radiimoon},#/r&],{{All,"Moons",All,"Radius"},{All,"Radius"}}]@planets;​​
planetsReplaceAtmm_
mm
radiimoon
,{All,2}

13
Add a density column to the Moons column

In[]:=
e4=QueryAll,<|#,"Moons"->QueryAll,<|"Mass"->#Mass,"Radius"->#Radius,"Density"->N#Mass
4
3
Pi#Radius^3|>&@#Moons|>&@e3;​​
e3All,MapAt#~Join~<|"Density"->N#Mass
4
3
Pi#Radius^3|>&,{"Moons",All}

14
Create a Dataset with all moons’ densities relative to earth’s

In[]:=
d=e4["Earth","Moons",1,"Density"];​​Join@@Query[Values,"Moons",All,#Density/d&]@e4//DeleteMissing//ReverseSort;​​
e4[Values/*Apply[Join]/*DeleteMissing/*ReverseSort,"Moons",All,#"Density"/d&]

15
Extract the properties of the Moon and Deimos

In[]:=
Extract[{{"Earth","Moons",{"Moon"}},{"Mars","Moons",{"Deimos"}}}]@planets//Dataset;​​
planets["Earth","Moons",{"Moon"}]~Join~planets["Mars","Moons",{"Deimos"}]

16
Select all moons with a larger mass than earth’s Moon

In[]:=
em=planets["Earth","Moons","Moon","Mass"];​​Join@@Query[All,"Moons",Select[#Mass>em&],{"Mass"}]@planets;​​
planets[Join@@#&,"Moons",Select[#Mass>em&],{"Mass"}]
In[]:=
Query[All,"Moons",Select[#Mass>planets["Earth","Moons","Moon","Mass"]&]/*Keys]@planets;​​
planets[All,"Moons",Select[#Mass>planets["Earth","Moons","Moon","Mass"]&]/*Keys]

17
Rename the planets mass and radius column headers

In[]:=
Query[All,KeyMap[Replace[{"Mass"->"PlanetMass","Radius"->"PlanetRadius"}]]]@planets;​​
planets[All,<|"PlanetMass"->"Mass","PlanetRadius"->"Radius","Moons"->"Moons"|>]

18 Replace the Moons’ mass and radius column headers

In[]:=
Query[All,<|#,"Moons"-><|Query[All,KeyMap[Replace[{"Mass"->"MoonMass","Radius"->"MoonRadius"}]]]@#Moons|>|>&]@planets;​​
planets[MapAt[<|"MoonMass"->#["Mass"],"MoonRadius"->#["Radius"]|>&,{All,3,All}]]

19
Rename the planets names to Latin ones

In[]:=
Query[KeyMap[Replace[{"Mercury"->"Mercurius","Venus"->"Lucifer","Earth"->"Terra","Mars"->"Martius","Jupiter"->"Lovis","Saturn"->"Saturnus","Neptune"->"Neptunus"}]],All]@planets;​​
planets[<|"Mercurius""Mercury","Lucifer""Venus","Terra""Earth","Martius""Mars","Lovis""Jupiter",
"Saturnus""Saturn","Uranus"->"Uranus","Neptunus""Neptune"|>]

20 Rename the two Mars moons to “satellite” 1 and 2

23 Remove Saturn’s moons

25 Remove the entire Moons’ mass column

28 Filter the planets Dataset by a moon mass criterion

29 Sort the planets by name

30 Sort the moons by name

31 Swap the planets’ mass and radius columns

32 Swap the moons’ mass and radius columns

33 Swap the row keys of Uranus and Saturn

34 Swap the row keys of Phobos and Deimos