On 27-May-2003 Jose Miguel Pérez wrote: <snip> > 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). > > The SELECT will produce the following result, as close as possible to > what you stated: > > age_range Name How_Many > ----------+-------+---------- > 1 | James | 1 > 1 | John | 2 > 3 | John | 1 > 3 | Rob | 3 > 4 | John | 2 > > (Please Note the lack of the "age_range" number 2: 15-29). >
SELECT ELT(1+ (age/15), '0-14', '15-29', '30-44', '45-59') AS age_range Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. (53kr33t w0rdz: sql table query) -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]