0

我有表测试有值

Status  |      DATE
  X     |   25-11-2012
  X     |   25-11-2012
  Y     |   25-11-2012
  Z     |   25-11-2012
  X     |   26-11-2012
  Y     |   26-11-2012
  Y     |   26-11-2012
  Z     |   26-11-2012

我想显示

   DATE      | X | Y | Z |
25-11-2012   | 2 | 1 | 1 |
26-11-2012   | 1 | 2 | 1 |

请帮助我。

4

1 回答 1

0
select 
  date_col, 
  count(case when status='X' then 1 end) as X,
  count(case when status='Y' then 1 end) as Y,
  count(case when status='Z' then 1 end) as Z
from your_table
group by date_col;
于 2012-11-27T13:15:03.100 回答