表1, tb_team
id name表2, tb_subscription
username teamId表3, tb_match
id hostTeamId awayTeamId 现在我就想获取到主客场球队的信息以及match的所有信息,sql语句应该怎么写?

解决方案 »

  1.   

    贴建表及插入记录的SQL,及要求结果出来看看try:
    select * from tb_subscription a left join teamId b on a.teamId=b.hostTeamId 
    left join teamId c on a.teamId=c.awayTeamId 
    where a.username='123'
      

  2.   

    select h.name,a.name
    from tb_match m ,tb_team h  , tb_team a, tb_subscription s
    where m.hostTeamId=h.id  and m.awayTeamId=a.id
    and m.hostTeamId=s.teamId and  m.awayTeamId=s.teamId
      

  3.   

    m.hostTeamId=s.teamId and m.awayTeamId=s.teamId 这样子的话不是主客场的球队是同一只了么,不是很理解
      

  4.   


    贴建表及插入记录的SQL,及要求结果出来看看
      

  5.   

    select h.name,a.name
    from tb_match m ,tb_team h  , tb_team a, tb_subscription s
    where m.hostTeamId=h.id  and m.awayTeamId=a.id
    and (m.hostTeamId=s.teamId or m.awayTeamId=s.teamId)
      

  6.   

    建立表的时候直接用workbench输入的