Skip to main content
formatting, spelling
Source Link
Alex Tennant
  • 13.7k
  • 5
  • 58
  • 85

For 2 especifcsspecific ages: SELECT sum(CASE WHEN Age_C between 20 and 29 THEN 1 ELSE 0 END) as Age2029, sum(CASE WHEN Age_C between 30 and 40 THEN 1 ELSE 0 END) as Age3040 from contact

SELECT sum(CASE WHEN Age_C between 20 and 29 THEN 1 ELSE 0 END) as Age2029, 
    sum(CASE WHEN Age_C between 30 and 40 THEN 1 ELSE 0 END) as Age3040 
from contact

OR for group by 10 years

select (convert(int,(Age_C/10))*10) as Age_from,(convert(int,(Age_C/10))*10+9) as Age_to, count(Age_C) as numberContacts from contact group by convert(int,(Age_C/10))

BR, Ostrowski

select (convert(int,(Age_C/10))*10) as Age_from,
    (convert(int,(Age_C/10))*10+9) as Age_to, 
    count(Age_C) as numberContacts 
from contact 
group by convert(int,(Age_C/10))

For 2 especifcs ages: SELECT sum(CASE WHEN Age_C between 20 and 29 THEN 1 ELSE 0 END) as Age2029, sum(CASE WHEN Age_C between 30 and 40 THEN 1 ELSE 0 END) as Age3040 from contact

OR for group by 10 years

select (convert(int,(Age_C/10))*10) as Age_from,(convert(int,(Age_C/10))*10+9) as Age_to, count(Age_C) as numberContacts from contact group by convert(int,(Age_C/10))

BR, Ostrowski

For 2 specific ages:

SELECT sum(CASE WHEN Age_C between 20 and 29 THEN 1 ELSE 0 END) as Age2029, 
    sum(CASE WHEN Age_C between 30 and 40 THEN 1 ELSE 0 END) as Age3040 
from contact

OR for group by 10 years

select (convert(int,(Age_C/10))*10) as Age_from,
    (convert(int,(Age_C/10))*10+9) as Age_to, 
    count(Age_C) as numberContacts 
from contact 
group by convert(int,(Age_C/10))
Source Link

For 2 especifcs ages: SELECT sum(CASE WHEN Age_C between 20 and 29 THEN 1 ELSE 0 END) as Age2029, sum(CASE WHEN Age_C between 30 and 40 THEN 1 ELSE 0 END) as Age3040 from contact

OR for group by 10 years

select (convert(int,(Age_C/10))*10) as Age_from,(convert(int,(Age_C/10))*10+9) as Age_to, count(Age_C) as numberContacts from contact group by convert(int,(Age_C/10))

BR, Ostrowski