Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

SQL GROUP BY Clause

by lex (Initiate)
on Sep 26, 2005 at 09:18 UTC ( #495038=perlquestion: print w/replies, xml ) Need Help??

lex has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: SQL GROUP BY Clause
by rnahi (Curate) on Sep 26, 2005 at 09:44 UTC

    You are desperately OT in this forum.

    Aside from that, let me analyze your question.

    Does the order of columns in a SQL Group By clause matter?

    Why would anyone ask somathing like that? If you were doing something practical with SQL, you could just throw two queries, changing the order of columns in the GROUP BY, and seeing for yourself if they differ or not (I am not going to give you the answer indirectly :-P).

    So youy were not doing anything practical. Then why would you be curious about this? The only plausible answer is because somebody asked you. Hence, it's homework.

    One more indication of homework is the "discuss" clause. You don't come to a forum and say "discuss" for something you don't know. You can come here, post something in Meditations, say what youy think about that, and then ask for discussion. But discussing some unknown thing that your teacher asks you to find out is hardly something that can tickle our willingness to help.

Re: SQL GROUP BY Clause
by planetscape (Chancellor) on Sep 26, 2005 at 09:30 UTC
    P.S. This is not a school essay that I want you to write for me.

    Say, that is convincing... ;-) Please see this.

    planetscape
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: SQL GROUP BY Clause
by rinceWind (Monsignor) on Sep 26, 2005 at 09:46 UTC

    lex: what do YOU think? What's your application? Whether is does matter or not depends on what you are wanting to achieve.

    Also, you have not said which database platform you are using, which would significantly affect the answer.

    P.S. This is not a school essay that I want you to write for me.

    What are you looking for then?

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: SQL GROUP BY Clause
by jZed (Prior) on Sep 27, 2005 at 01:32 UTC
    As you can see from people's (lack of) response, if you want discussion, you might be better off giving your own thoughts to kick the discussion into gear. That said, my guess is that no, the order should not matter. If you group SUM(sales) by "year, region", you are asking to see totals for each year and totals for each region and if you group them by "region, year", you are still asking for totals for each region and for each year (in other words, the same two totals). Is that what you'd expect? What about it merits discussion?
Re: SQL GROUP BY Clause
by chrism01 (Friar) on Sep 27, 2005 at 06:53 UTC
    I agree it sounds a lot like homework....
    however, .. yes it matters.
    The reason is SQL presents the results grouped (nested) in the order you asked, so SALES grouped by yr, mth would group sales by yr, then by mth within that yr. Evidently the other way round would make no sense unless you were looking for seasonal patterns...
    Because it's easier to code group by internally by first sorting the data as per request, group by normally implies order by the same values will occur in the output.
Re: SQL GROUP BY Clause
by xorl (Deacon) on Oct 05, 2005 at 16:22 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://495038]
Approved by monkfan
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2023-12-10 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (38 votes). Check out past polls.

    Notices?