ID | SalesID | CityID | Money |
1 | 10 | 20 | 1000 |
2 | 10 | 22 | 2000 |
3 | 11 | 20 | 4000 |
4 | 11 | 22 | 8000 |
5 | 10 | 20 | 3000 |
6 | 10 | 22 | 5000 |
7 | 11 | 20 | 7000 |
8 | 11 | 22 | 9000 |
select from table SalesID,CityID,Sum(Money) Groupby SalesID,CityID
-- or
select from table SalesID,CityID,Sum(Money) Groupby CityID, SalesID
Those should vary only in output order of the summed rows. The danger of automatic grouping is when/if someone picks "ID" in the select list... then it all goes to heck. The "common case" for Group By is to list all columns not aggregated in the select_column clause. Automatically forcing group-by seems to be almost assuredly doomed to run into keys and foreign-keys when they are incorrectly added to the columns list.
In your limited case, tho, I'm thinking you're safe.
--
$you = new YOU;
honk() if $you->love(perl)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|