Match赛程表:        MatchID    赛程id          主键
        hostTeamId      主队ID     
        guestTeamId     客队ID
        MatchResult     比赛结果     (值为2:0)
        MatchTime       比赛时间
        
      Team
       TeamID      参赛队的id      主键
       TeamName    参赛队的名字    (队名分别是:拜伦   、不来梅)
-------------------------------------------
   Match表中的hostTeamId和guestTeamId与Team表中TeamID是有关联的 用sql语句查询2008-6-1 到2008-7-31的结果是
   拜伦 2:0 不来梅  2008-6-23

解决方案 »

  1.   

    select t1.teamname,matchresult,t2.teamname,matchtime
    from match m,team t1,team t2
    where t1.teamid=m.teamid  and t2.teamid=m.teamid
      

  2.   

    select t1.teamname,matchresult,t2.teamname,matchtime 
    from match m,team t1,team t2 
    where t1.teamid=m.teamid  and t2.teamid=m.teamid
    and t1.matchtime between '2008-6-1' and '2008-6-23'
      

  3.   

    select t1.teamname,matchresult,t2.teamname,matchtime 
    from match m,team t1,team t2 
    where t1.teamid=m.teamid  and t2.teamid=m.teamid 
    and to_cahr(t1.matchtime,'yyyy-mm-dd')>'2008-6-1' and to_cahr(t1.matchtime,'yyyy-mm-dd')<'2008-6-23'
      

  4.   


    select t1.Teamname,m.MstchResult,t2.Teamname,Matchtime from match m,team t1,team t2 
    where t1.Teamname=m.hostTeamId 
    and t2.Teamname=m.guestTeamId  
    and MatchTime>'1-jun-09' 
    and MatchTime>'31-jul-09' ;
      

  5.   

    这种做法在数据量巨大时非常低效
    海量数据检索时不要用to_char等格式转换
      

  6.   

    select t1.Teamname,m.MatchResult,t2.Teamname,Matchtime from match m,team t1,team t2 
    where t1.Teamname=m.hostTeamId 
    and t2.Teamname=m.guestTeamId  
    and MatchTime>'01-jun-09' 
    and MatchTime<'31-jul-09' ;
      

  7.   


    select t1.teamname,matchresult,t2.teamname,matchtime 
    from match m,team t1,team t2 
    where t1.teamid=m.teamid  and t2.teamid=m.teamid 
    and t1.matchtime between '2008-6-1' and '2008-7-31'
      

  8.   

    如果 MatchTime 是日期类型的话,你这里也一样用不了index,隐性转型了
    可以t1.matchtime between to_date('2008-6-1', 'yyyy-mm-dd') and to_date('2008-7-31', 'yyyy-mm-dd')
    ================================================================== 
    Inthirties关注Oracle数据库 维护 优化,安全,备份,恢复,迁移,故障处理 如果你需要帮助或想和我一起学习的请联系 
    联系方式QQ:370140387 
    QQ群:  85837884(注明:数据库) 
    电子邮件:[email protected] 
    网站: http://www.inthirties.com
      

  9.   

    发表于:2009-05-11 12:39:483楼 得分:0 
    select t1.teamname,matchresult,t2.teamname,matchtime 
    from match m,team t1,team t2 
    where t1.teamid=m.teamid  and t2.teamid=m.teamid 
    and t1.matchtime between '2008-6-1' and '2008-6-23'