T-SQL 2或更多在同一表上的联接

时间:2018-11-22 16:15:03

标签: tsql join

im试图在同一张桌子上做两个左联接,但它不起作用,我也不知道为什么...

有人可以帮我吗?

那是我的代码:

CREATE VIEW [dbo].[Sportwetten_Data] 
AS 
  SELECT TOP 1000 Main.id                                         AS id, 
                  Main.date                                       AS date, 
                  Concat(Main.hometeam, ' - ', Main.awayteam)     AS event, 
                  Concat(Goals.homescored, '/', Goals.homeconceded, ' - ', 
                  Goals.awayscored, '/', 
                  Goals.awayconceded)                             AS goals, 
                  LB.bet                                          AS bet, 
                  Main.entry                                      AS entry, 
                  Main.odd                                        AS odd, 
                  Concat(Result.homegoals, ':', Result.awaygoals) AS result, 
                  LS.type                                         AS status 
  FROM   Main, 
         Goals, 
         Result, 
         Main AS M 
         LEFT JOIN Lookup_Bettype LB 
                ON M.bettype = LB.bettype 
         LEFT JOIN Lookup_Status LS 
                ON M.status = LS.type 
  WHERE  Main.id = Goals.id 
  ORDER  BY Main.id ASC 

一切正常,除了

LEFT JOIN Lookup_Status LS 
                    ON M.status = LS.type 

当然

LS.type                                         AS status 

1 个答案:

答案 0 :(得分:0)

几个月前,我遇到了与您的联接类似的问题:

  

FROM Main,            目标,            结果,            主AS M

尝试显式表示这些表之间的联接。为我工作