sql中group by的用法

数据库表table
日期 胜负
2009-12-9 胜
2009-12-9 胜
2009-12-9 负
2009-12-9 负
2009-12-10 负
2009-12-10 胜
2009-12-10 负

查询结果
日期 胜 负
2009-12-9 2 2
2009-12-10 1 2

SQL如何写?哪位大哥指教下,谢谢

[code="sql"]
select 日期,
sum(decode(胜负,'胜',1,0)),
sum(decode(胜负,'负',1,0))
from 数据库表
group by 日期
[/code]

select datetable.'日期',t1.'胜',t2.'负' from
(select '日期' from table group by '日期') datetable,
(select count(*) as '胜' from table where '胜负'='胜' and '期'=datetable.'日期') t1
,(select count(*) as '负' from table where '胜负'='负'
and '日期'=datetable.'日期') t2

我没试,你拿去试一下。

[code="sql"]
select datetable.'日期',t1.'胜',t2.'负' from
(select '日期' from table group by '日期') datetable,
(select count(*) as '胜' from table where '胜负'='胜' and '日期'=datetable.'日期') t1
,(select count(*) as '负' from table where '胜负'='负'
and '日期'=datetable.'日期') t2
[/code]

加一下空格

select 日期,(select count(胜负) from table where 胜负='胜' and t.日期=table.日期)as success,(select count(胜负) from table where 胜负='负' and t.日期=table.日期) as failure from table t group by 日期;

[code="sql"]
select 日期,

sum(case 胜负 when 胜 then 1 end),

sum(case 胜负 when 负 then 1 end)

from 数据库表

group by 日期

[/code]

unika_ly12 (中级程序员) 的做法应该没有问题