【发布时间】:2014-02-18 16:27:00
【问题描述】:
我有一个如下格式的足球赛程表。
date date primary key
homescore int(4)
awayscore int(4)
数据按以下格式存储
DATE | HOMESCORE | AWAYSCORE
------------------------------------------
01-01-2014 | 1 | 0
08-01-2014 | 2 | 1
15-01-2014 | 1 | 1
22-01-2014 | 3 | 2
29-01-2014 | 0 | 0
06-02-2014 | 1 | 3
等等……
我想运行一个查询来返回赢、输和平局的总数。
select count(*) as won from fixtures where homescore > awayscore;
select count(*) as lostfrom fixtures where homescore < awayscore;
select count(*) as drawnfrom fixtures where homescore = awayscore;
这个单一查询的结果看起来像......
Won Lost Drawn
3 1 2
请有人给我一些帮助。
【问题讨论】:
标签: mysql sql select count case