New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken exercise requiring a subquery #255

Open
Denubis opened this Issue Jul 6, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@Denubis
Contributor

Denubis commented Jul 6, 2018

Hi folks. Just noting this here because it was a major trap in the lesson.

In 06-agg,

The function group_concat(field, separator) concatenates all the values in a field using the specified separator character (or ‘,’ if the separator isn’t specified). Use this to produce a one-line list of scientists’ names, such as:

William Dyer, Frank Pabodie, Anderson Lake, Valentina Roerich, Frank Danforth
Can you find a way to order the list by surname?

is broken. The answer requires a subquery:

SELECT group_concat(name, ', ') FROM (select personal||' '||family as name from person order by family);

And we never teach the idea of subqueries in the lesson. I riffed on this because it helped flow into the VIEWs needed by my edits to the capstone, but I recommend that this exercise be cut, because it's a trap for unwary instructors.

(Basically, because order by runs on the output rows, not the input rows, we need to sort the input data before we hit the aggregation step.)

Just dropping in post-workshop feedback, because I don't have time to edit this in properly to the lesson, and I think it'd introduce way too much cognitive load.

@remram44

This comment was marked as off-topic.

Collaborator

remram44 commented Jul 6, 2018

No subquery is required 😉

@remram44

This comment has been minimized.

Collaborator

remram44 commented Jul 6, 2018

Oh I see, a subquery is required IF you want to order. Yes, that is unfortunate. Should the question be tweaked to producing the list out of order?

@Denubis

This comment has been minimized.

Contributor

Denubis commented Jul 6, 2018

Hi Remi,

I think having summative exercises here is a good thing. And this teaches pivoting with group_concat. If it's just "Hey I can use more aggregation methods, and this one is called group_concat" then I think it works well. So both routes work. Maybe copy this one to one of the final exercises with discussion of subqueries in a todo and leave a non-ordered version here?

donalus pushed a commit to donalus/sql-novice-survey that referenced this issue Oct 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment