---
title: "case then sql"
author: "yaoweinan"
date: "2011-08-05T17:51:36Z"
tags: []
categories: ["非技术"]
slug: "case-then-sql"
draft: false
lastmod: "2012-06-04T23:53:57Z"
id: 1141249
url: "https://ilyon.iteye.com/blog/1141249"
---

&lt;!--StartFragment --&gt;

   得到&lt;!--StartFragment --&gt;

 的sql

select t.date,sum(case when t.score='胜' then 1 else 0 end) 胜,sum(case when t.score='败' then 1 else 0 end) 败  
 from test t group by t.shijain;