数据库表:sql
select * from rec order by rst,game_time;数据库
ID | GAME_TIME | RST |
---|---|---|
2 | 01-1月 -11 | F |
6 | 01-1月 -11 | F |
3 | 02-1月 -11 | F |
9 | 02-1月 -11 | F |
7 | 03-1月 -11 | F |
1 | 01-1月 -11 | W |
4 | 01-1月 -11 | W |
8 | 01-1月 -11 | W |
5 | 02-1月 -11 | W |
要求结果:函数
比赛日期 | 结果 | 结果统计 |
---|---|---|
02-1月 -11 | 失败 | 2 |
03-1月 -11 | 失败 | 1 |
02-1月 -11 | 胜利 | 1 |
01-1月 -11 | 失败 | 2 |
01-1月 -11 | 胜利 | 3 |
写出SQL1:decode函数code
select game_time as 比赛日期, decode(rst,'F','失败','W','胜利','无结果') as 结果, count(rst) as 结果统计 from rec group by game_time,rst;
SQL2:case语句:table
select game_time as 比赛日期, (case rst when 'W' then '胜利' when 'F' then '失败' else '无结果' end)结果, count(rst) as 结果统计 from rec group by game_time,rst;
记录下:
decode(表达式1,条件1,结果1,条件2,结果2);class
---[2013-07-02]---select