List:General Discussion« Previous MessageNext Message »
From:Jon Haugsand Date:May 27 2003 12:11pm
Subject:Re: group by
View as plain text  
* Jose Miguel Pérez
>         SELECT
>               CASE
>                    WHEN age < 15 THEN 1
>                    WHEN age BETWEEN 15 AND 29 THEN 2
>                    WHEN age BETWEEN 30 AND 45 THEN 3
>                    WHEN age > 45 THEN 4
>               END AS age_range,
>               name,
>               COUNT(*) as how_many
>          FROM test
>          GROUP BY age_range, name
>
>     Note that in the above SELECT, we feed the GROUP BY a number
> representing the age range (age_range).

One thing I never have understood w.r.t. GROUP BY is why the SQL
engine do not find the group by elements.  You don't seem to have any
choice do you?  I mean if you do a select:

SELECT a,b,c,d,MAX(e),COUNT(*),AVERAGE(f) FROM foo WHERE something
GROUP BY a,b,c,d;

That is, you _have to_ group by all columns that are not a function
extracting something from all columns.

-- 
 Jon Haugsand, Jon-H.Haugsand@stripped
 http://www.norges-bank.no

Thread
group byRob27 May
  • Re: group byJose Miguel Pérez27 May
    • RE: group byRob27 May
    • Re: group byJon Haugsand27 May
    • Re: group byDon Read27 May
  • Re: group byJose Miguel Pérez27 May
    • Re: group byJon Haugsand27 May
  • Re: group byJose Miguel Pérez27 May
    • Re: group byJon Haugsand27 May
  • Re: group byJose Miguel Pérez27 May