Skip to content

Commit b4c7022

Browse files
authored
Merge pull request #170 from tracykteal/gh-pages
nesting solution in challenge in 03 lesson
2 parents 211f1d9 + 4896bc4 commit b4c7022

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

_episodes/03-sql-joins-aliases.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -291,25 +291,23 @@ but using `AS` is much clearer so it is good style to include it.
291291
> 7. What is the average hindfoot length for male and female rodent of each species? Is there a Male / Female difference?
292292
>
293293
> 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;`
304294
>
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`
312+
> {: .solution}
313+
{: .challenge}

0 commit comments

Comments
 (0)