2017-05-02 4 views
0

SQL을 통해 테이블을 가지고 놀기 위해 MS Access를 사용하고 있습니다. 나는 나의 테이블을 적절하게 그룹화하고 싶습니다. 그리고 이것은 제가하고 싶은 것을 보여주는 예입니다. 다음과 같은 표가 있다고 가정 해 보겠습니다.sql 테이블을 올바르게 그룹화하십시오.

Cool? | Age 
Yes | 15 
No | 34 
No | 12 
Yes | 26 
Yes | 10 

원하는 결과는 얼마나 많은 ppl이 멋지냐, 나이별로 분류되지 않았는가를 보여주는 결과 테이블입니다. 예를 들어이 예에서는 다음과 같습니다.

AGE | Count that are cool | Count that is Not cool 

<25 |   2    |   1 

>=25 |   1    |   1 

미리 감사드립니다.

답변

4

이 시도 :

case when age<25 then '<25' when age>=25 then '>=25' end as age, count(case when age<25 then 1 else null end) as [Count that are cool], count(case when age>=25 then 1 else null end) as [Count that is Not cool] 
    from Table1 
    group by case when age<25 then '<25' when age>=25 then '>=25' end 
관련 문제