日期:2014-05-16 浏览次数:20678 次
create table m( mid int primary key auto_increment, hid int, gid int, result varchar(50), mtime date );
insert into m (hid,gid,result,mtime) values (1,2,'2:0','2006-05-21'), (2,3,'1:2','2006-06-21'), (3,1,'2:5','2006-05-25'), (2,1,'3:2','2006-07-21');
create table t( tid int, tname varchar(10) );
insert into t values (1,'巴萨'), (2,'皇马'), (3,'野马队');
select hid, result, gid,mtime from m;
select hid,tname, result,gid,mtime from m left join t on m.hid = t.tid;
select hid,t1.tname as '主队', result,gid,t2.tname as '客队',mtime from m left join t as t1 on m.hid = t1.tid left join t as t2 on m.gid = t2.tid;
select t1.tname as '主队',result as '比分',t2.tname as '客队',mtime as '比赛时间' from m left join t as t1 on m.hid = t1.tid left join t as t2 on m.gid = t2.tid;
select t1.tname as '主队',result as '比分',t2.tname as '客队',mtime as '比赛时间' from m left join t as t1 on m.hid = t1.tid left join t as t2 on m.gid = t2.tid where mtime between '2006-06-01' and '2006-07-01';