# 비율 그래프 차트 그리기 (카테고리 분포)

**URL:** <https://ask.selectfromuser.com/t/topic/43>\
**Category:** 사용 팁\
**Tags:** chart\
**Created:** [6월 28, 2023, 10:14오전 UTC](https://ask.selectfromuser.com/t/topic/43 "2023-06-28T10:14:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhlee](https://yyz2.discourse-cdn.com/flex032/user_avatar/ask.selectfromuser.com/jhlee/32/20_2.png) [@jhlee](https://ask.selectfromuser.com/u/jhlee)\
**Post date:** [6월 28, 2023, 10:14오전 UTC](https://ask.selectfromuser.com/t/topic/43/1 "2023-06-28T10:14:10Z")

</div>

전체 사용자 중 활성/비활성 비율이나  
구매 상품중 카테고리 분포등 다양하게 활용되는 지표 그래프를 그립니다.  
대시보드에 주로 사용됩니다.

```auto
resource: mysql.qa
name: category
display: metric
sql: > 
  SELECT count(id) as 'c'
  FROM PropertyProfile
  GROUP BY ISNULL(`signed_at`)
  ORDER BY 1 DESC
metricOptions:
  type: category
  names: 
    - Active users
    - Inactive users
  value: c
  total: 전체 사용자

```

 ![Screenshot 2023-06-22 at 2.53.11 PM](https://canada1.discourse-cdn.com/flex032/uploads/selectfromuser/original/1X/4f63158ddd78c25ac4f352c4848de59d574f3cbc.png)

---

<div class="post-metadata">

**Author:** ![null75](https://avatars.discourse-cdn.com/v4/letter/n/22d042/32.png) [@null75](https://ask.selectfromuser.com/u/null75)\
**Post date:** [3월 11, 2025, 4:45오전 UTC](https://ask.selectfromuser.com/t/topic/43/2 "2025-03-11T04:45:19Z")

</div>

예제코드에서 Inactive users 데이터는 어디서 가져오고 있는 건가요?

---

<div class="post-metadata">

**Author:** ![hbkim](https://yyz2.discourse-cdn.com/flex032/user_avatar/ask.selectfromuser.com/hbkim/32/23_2.png) [@hbkim](https://ask.selectfromuser.com/u/hbkim)\
**Post date:** [3월 11, 2025, 6:19오전 UTC](https://ask.selectfromuser.com/t/topic/43/3 "2025-03-11T06:19:39Z")

</div>

안녕하세요. 위 예제는 조회된 값을 순서대로 names 순서에 맞게 label 처리를 하게 됩니다. (ORDER BY 1 DESC: 값이 큰 순서대로 Active users, Inactive users 에 맞게 표시)

추가로 아래와 같이 특정 컬럼(필드)의 값에 따라 그룹(GROUP BY)하여 순서대로 표기할 수도 있습니다.

```yaml
  - type: query
    resource: mysql.qa
    name: category
    display: metric
    sql: > 
      SELECT `type`, count(id) as 'c'
      FROM PropertyProfile
      WHERE `type` IS NOT NULL
      GROUP BY `type`
      ORDER BY 2 DESC
    metricOptions:
      type: category
      name: type
      value: c
      total: 타입 분포

```

추가로 도움이 필요하신 경우 말씀해주세요. 감사합니다.
