---
title: "sql 统计总数和各状态数"
author: "kingmxj"
date: "2010-04-22T14:47:19Z"
tags: ["SQL"]
categories: ["数据库"]
slug: "sql"
draft: false
lastmod: "2010-04-22T14:47:19Z"
id: 650457
url: "https://kingmxj.iteye.com/blog/650457"
---

select g.dept_id,
count(g.dept_id) as '总数',
sum(case g.is_deal when '0' then 1 else 0 end) as '办理',
sum(case g.is_deal when '1' then 1  else 0 end) as '未办理'
from getnumber g where g.style='0' or g.style is null
group by g.dept_id