一个sql问题的解决
create table bishai(id int(11) AUTO_INCREMENT, time varchar(64),fengshu int(4),primary key(id));insert into bishai(time,fengshu) values('2005-05-09','胜'),('2005-05-09','胜'),('2005-05-09','负'),('2005-05-09','负'),('2005-05-10','胜'),('2005-05-10','负'),('2005-05-10','bishai负');
?注意这个地方,使用了多个values,使用带有多个VALUES列表的INSERT语句一次插入几行这将比使用一个单行插入语句快几倍。
我的sql如下:
select time as '比赛时间', sum(case when fengshu = '胜' then 1 else 0 end) '胜',sum(case when fengshu = '负' then 1 else 0 end) '负'from bishaigroup by timeorder by time;
?
select time,sum(score1),sum(score2) from (select time,decode(fengshu,'胜',1,0) score1,decode(fengshu,'负',1,0) score2 from a) group by time