---
title: "分别统计每组中某一列大于0的值和少于0的值"
author: "devilhand"
date: "2010-06-09T22:58:43Z"
tags: []
categories: ["数据库"]
slug: "0-0"
draft: false
lastmod: "2010-06-09T22:58:43Z"
id: 688417
url: "https://devilhand.iteye.com/blog/688417"
---

数据  
![](http://dl.iteye.com/upload/attachment/262303/2fdfeb2f-4dc7-3815-8f50-be5ad518f8a5.bmp)  
 

```
select name, sum(case  when Q>0 then Q end) as A,sum(case when Q<0 then Q end) as B from ttt group by name
```

 结果  
![](http://dl.iteye.com/upload/attachment/262305/65beef87-922f-3618-969e-fc90d875032d.bmp)