Select With the range of Ages

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Thu, 22 Jun 2006 11:04 am

I have a select that returns:
Code: Select all
select idade,count(*)
from cliente
group by idade
IDADE    COUNT(*)
10   2
15   5
17   6
20   1
22   5
32   2
would like him returned AGE COUNT (*) 10 20 21 14 ... 35.7 without using any tables of tracks this is possible using some kind of group by or another method?
Spectreman
Location: Tóquio

DOMINANTES, ÀS ORDENS!

Poston Thu, 22 Jun 2006 2:01 pm

I worked out
Code: Select all
SELECT
SEXO,
(CASE
WHEN idade BETWEEN 0  AND 15 THEN ' 0 a 15 '
WHEN idade BETWEEN 16 AND 20 THEN ' 16 - 20 '
WHEN idade BETWEEN 21 AND 35 THEN ' 21 - 35 '
WHEN idade BETWEEN 36 AND 49 THEN ' 36 - 49 '
ELSE
   ' ACIMA DE 50 '
END)
AS BUCKET,
SUM(QUANT) AS TOTAL
FROM X
GROUP BY SEXO,
(CASE
WHEN idade BETWEEN 0  AND 15 THEN ' 0 a 15 '
WHEN idade BETWEEN 16 AND 20 THEN ' 16 - 20 '
WHEN idade BETWEEN 21 AND 35 THEN ' 21 - 35 '
WHEN idade BETWEEN 36 AND 49 THEN ' 36 - 49 '
ELSE
   ' ACIMA DE 50 '
END)
Spectreman
Location: Tóquio

DOMINANTES, ÀS ORDENS!


  • See also
    Replies
    Views
    Last Post


Return to SQL

Who is online

Users browsing this forum: No registered users and 2 guests