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!

解决方案 »

  1.   

    SELECT Team.teamName,matchResult,Team_2.teamName,matchTime
    FROM Team INNER JOIN Match ON Team.teamId=Match.hostTeamId INNER JOIN Team Team_2
        on Match.guestTeamId=Team_2.teamId
      

  2.   

    select teamName Name1,matchResult,teamName Name2,matchTime
    from Match inner join Team 
    on (matchTime > '2007-6-1') and (matchTime < '2007-7-1')
    order by matchTime
      

  3.   

    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' 
      

  4.   

    还是用直观的
    select a.teamName Name1,matchResult,b.teamName Name2,matchTime
    from Match left join team a on a.teamid=guestTeamId left join team b on b.teamid=guestTeamId
    where matchTime>'2007-6-1' and matchTime< '2007-7-1'
      

  5.   

    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'