---
title: "行转列"
author: "fish8077"
date: "2011-07-19T13:42:43Z"
tags: []
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2011-07-19T13:42:43Z"
id: 1127864
url: "https://fish8077.iteye.com/blog/1127864"
---

```sql

select customid,   
    count(case status when 0 then status else null end) as status-0,   
    count(case status when 1 then status else null end) as status-1,   
    count(case status when 2 then status else null end) as status-2   
    from custom group by customid.  

```