You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _episodes/03-sql-joins-aliases.md
+19-21Lines changed: 19 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -291,25 +291,23 @@ but using `AS` is much clearer so it is good style to include it.
291
291
> 7. What is the average hindfoot length for male and female rodent of each species? Is there a Male / Female difference?
292
292
>
293
293
> 8. What is the average weight of each rodent species over the course of the years? Is there any noticeable trend for any of the species?
294
-
{: .challenge}
295
-
296
-
297
-
> ## Proposed solutions:
298
-
>
299
-
> 1. Solution: `SELECT plot_type, count(*) AS num_plots FROM plots GROUP BY plot_type ORDER BY num_plots DESC;`
300
-
>
301
-
> 2. Solution: `SELECT year, sex, count(*) AS num_animal FROM surveys WHERE sex IS NOT null GROUP BY sex, year;`
302
-
>
303
-
> 3. Solution: `SELECT species_id, plot_type, count(*) FROM surveys JOIN plots ON surveys.plot_id=plots.plot_id WHERE species_id IS NOT null GROUP BY species_id, plot_type;`
304
294
>
305
-
> 4. Solution: `SELECT taxa, AVG(weight) FROM surveys JOIN species ON species.species_id=surveys.species_id GROUP BY taxa;`
306
-
>
307
-
> 5. Solution: `SELECT taxa, 100.0*count(*)/(SELECT count(*) FROM surveys) FROM surveys JOIN species ON surveys.species_id=species.species_id GROUP BY taxa;`
308
-
>
309
-
> 6. Solution: `SELECT surveys.species_id, MIN(weight) as min_weight, MAX(weight) as max_weight, AVG(weight) as mean_weight FROM surveys JOIN species ON surveys.species_id=species.species_id WHERE taxa = 'Rodent' GROUP BY surveys.species_id;`
310
-
>
311
-
> 7. Solution: `SELECT surveys.species_id, sex, AVG(hindfoot_length) as mean_foot_length FROM surveys JOIN species ON surveys.species_id=species.species_id WHERE taxa = 'Rodent' AND sex IS NOT NULL GROUP BY surveys.species_id, sex;`
312
-
>
313
-
> 8. Solution: `SELECT surveys.species_id, year, AVG(weight) as mean_weight FROM surveys JOIN species ON surveys.species_id=species.species_id WHERE taxa = 'Rodent' GROUP BY surveys.species_id, year;`
314
-
{: .solution}
315
-
295
+
> > ## Proposed solutions:
296
+
> >
297
+
> > 1. Solution: `SELECT plot_type, count(*) AS num_plots FROM plots GROUP BY plot_type ORDER BY num_plots DESC`
298
+
> >
299
+
> > 2. Solution: `SELECT year, sex, count(*) AS num_animal FROM surveys WHERE sex IS NOT null GROUP BY sex, year`
300
+
> >
301
+
> > 3. Solution: `SELECT species_id, plot_type, count(*) FROM surveys JOIN plots ON surveys.plot_id=plots.plot_id WHERE species_id IS NOT null GROUP BY species_id, plot_type`
302
+
> >
303
+
> > 4. Solution: `SELECT taxa, AVG(weight) FROM surveys JOIN species ON species.species_id=surveys.species_id GROUP BY taxa`
304
+
> >
305
+
> > 5. Solution: `SELECT taxa, 100.0*count(*)/(SELECT count(*) FROM surveys) FROM surveys JOIN species ON surveys.species_id=species.species_id GROUP BY taxa`
306
+
> >
307
+
> > 6. Solution: `SELECT surveys.species_id, MIN(weight) as min_weight, MAX(weight) as max_weight, AVG(weight) as mean_weight FROM surveys JOIN species ON surveys.species_id=species.species_id WHERE taxa = 'Rodent' GROUP BY surveys.species_id`
308
+
> >
309
+
> > 7. Solution: `SELECT surveys.species_id, sex, AVG(hindfoot_length) as mean_foot_length FROM surveys JOIN species ON surveys.species_id=species.species_id WHERE taxa = 'Rodent' AND sex IS NOT NULL GROUP BY surveys.species_id, sex`
310
+
> >
311
+
> > 8. Solution: `SELECT surveys.species_id, year, AVG(weight) as mean_weight FROM surveys JOIN species ON surveys.species_id=species.species_id WHERE taxa = 'Rodent' GROUP BY surveys.species_id, year`
0 commit comments