日期:2014-05-19  浏览次数:20431 次

[求助]两个表之间的联查
Match表:有字段   matchId,   hostTeamId,   guestTeamId,   matchResult,   matchTime;
Team表:有字段   teamId,   teamName;
查处2006-6-1到2006-7-1之间的所有比赛,   并根据时间排序,   格式为   曼联   2:1   切尔西   2006-6-1

我这里写了一个sql查询但是不对,希望大家帮我该一下:
select   Team.Name,   Match.match.matchResult,   Team2.Name,   Match.matchTime
from   Match   inner   join
                Team   Team2   on   Match.hostTeamId   =   Team.teamId   and   Match.guestTeamId   =   Team2.teamId
where   (Match.matchTime   >   '2007-6-1 ')   and   (Match.matchTime   <   '2007-7-1 ')
order   by   Match.matchTime

                thx!

------解决方案--------------------
selet matchid, (select teamName from team where team.id = m.hostteamid) as hostteamname, (select teamName from team where team.id = m.guestteamid) as guestteamname , matchresult, matchtime from match m
where matchTime > '2007-6-1 '
and Match.matchTime < '2007-7-1 '