More GROUP BY

  • Comments posted to this topic are about the item More GROUP BY

  • This was removed by the editor as SPAM

  • Easy.. Thanks

  • Nice question, but awarding points for and titling "Group by" is a big hint, so alternatives without group should be automatically excluded.

    Anyway nice question and nice count distinct trick.

  • l.vignando (3/24/2016)


    Nice question, but awarding points for and titling "Group by" is a big hint, so alternatives without group should be automatically excluded.

    Anyway nice question and nice count distinct trick.

    Nice question. However, I've seen using the title as a hint produce the wrong result before. Yes, it was a hint here, but not always. 😉

  • The explanation excludes the DISTINCT keyword, which might be confusing if you didn't already know the correct answer.

  • Interesting question. The wrong answers were obvious. But the right answer I had to think about. I've never constructed a query like that before, using distinct in the HAVING clause's COUNT. I've used it in a simple select COUNT(distinct..., just not with the HAVING part.

  • Really, really easy. Thanks, Steve!

  • I think with the current data model and lack of constraints you would actually want both.

    WHERE Played = 'Rock' OR Played = 'Paper' OR Played = 'Scissors'

    GROUP BY Person HAVING COUNT(DISTINCT Played) = 3

    but the group by is key to the solution.

  • Shouldn't it be COUNT(DISTINCT Played) >= 3, in case some decides to play 'switch kick to the nuts'? 😛

  • Nice question, Steve. However, it won't work if the players are playing Rock, Paper, Scissors, Lizard, Spock. 🙂

  • Joel Ewald (3/24/2016)


    I think with the current data model and lack of constraints you would actually want both.

    WHERE Played = 'Rock' OR Played = 'Paper' OR Played = 'Scissors'

    GROUP BY Person HAVING COUNT(DISTINCT Played) = 3

    but the group by is key to the solution.

    Good catch!

  • stephen.long.1 (3/24/2016)


    Nice question, Steve. However, it won't work if the players are playing Rock, Paper, Scissors, Lizard, Spock. 🙂

    I deliberately left that out for another day.

  • Good easy way to end the week (wishing it was Friday), but the query would error in all cases:

    the table is created as [RPSGame], but the FROM clause references [RPSGames]. Too bad/so sad.

    So ha! I caught the trick!

    Mark
    Just a cog in the wheel.

  • starunit (3/24/2016)


    Good easy way to end the week (wishing it was Friday), but the query would error in all cases:

    the table is created as [RPSGame], but the FROM clause references [RPSGames]. Too bad/so sad.

    So ha! I caught the trick!

    Thanks. Corrected.

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic. Login to reply