Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • SELECT foo, bar, SUM(quux) FROM qux GROUP BY foo, bar;

    SELECT foo, bar, SUM(quux) FROM qux GROUP BY bar, foo;

    SELECT foo, SUM(quux) FROM qux GROUP BY foo, bar;

    SELECT foo, SUM(quux) FROM qux GROUP BY bar;
    • Maybe I need the comments to clue me in. The last two won't work ... is your point that in such an instance having the GROUP BY allows the programmer to figure out what the previous programmer meant and correct? Because I thought I clearly limited myself to talking about interactive, one-shot queries. This is like requiring strict for a perl-one liner. :)

      As near as I can tell, there is no difference between the first two, although I'm willing to be enlightened. I may just be sleepy on this early Monday morning.

      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
      • Why won’t the last two work?

        As for the first two, you’re right, there is no difference. Order matters when you use window functions, but not in ordinary grouping.

        • Never mind, they will. It's just not something I do often. And I think you've shown me why that clause can't be made optional. Of course, I'd prefer that it be made optional and that expressing the fields to group by in the SELECT be made mandatory, but I guess that would probably bork a lot of people up. :)

          --
          J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers