我有点迷失在这里我需要加入两个连接查询来形成一个表。这是我正在制作的剧本......
SELECT Email, Domain, site.SiteID, site.SiteName, Status, LastLogin, up.UPID, up.UPName, trd.TRMCID, trd.TRMCName
FROM UserDetails as ud
INNER JOIN SiteLocation as site
on ud.SiteID = site.SiteID
INNER JOIN UltimateParent as up
on ud.UPID = up.UPID
INNER JOIN TRMCDetails as trd
on ud.TRMCID = trd.TRMCID
SELECT SiteID, cinfo.CountryCode, Country
From Country as cntry
INNER JOIN CountryInfo as cinfo
on cntry.CountryCode = cinfo.CountryCode
INNER JOIN SiteLocation as site2
on cntry.CountryCode = site2.CountryCode
我需要显示国家/地区,但国家/地区代码与SiteID相关联。我很难加入他们两个。
这是第一个看起来像
的表电子邮件域-SITEID-SITENAME-STATUS-LLogin-UPID-UPNAME-TRMCID-TRMCName
这是第二个表格
SITEID-COUNTRYCODE国
我需要第三个表看起来像这样
电子邮件域-SITEID-SITENAME-STATUS-LLogin-UPID-UPNAME-TRMCID-TRMCName国
但是,我在组合我之前制作的两个连接时遇到了麻烦。
提前感谢您的帮助!
干杯!
答案 0 :(得分:1)
尝试赞:
SELECT
Email,
Domain,
site.SiteID,
site.SiteName,
Status,
LastLogin,
up.UPID,
up.UPName,
trd.TRMCID,
trd.TRMCName,
cinfo.CountryCode,
cntry.Country
FROM UserDetails as ud
INNER JOIN UltimateParent up on ud.UPID = up.UPID
INNER JOIN TRMCDetails trd on ud.TRMCID = trd.TRMCID
INNER JOIN CountryInfo cinfo on cntry.CountryCode = cinfo.CountryCode
INNER JOIN SiteLocation site on ud.SiteID = site.SiteID
INNER JOIN Country cntry on cntry.CountryCode = site.CountryCode
答案 1 :(得分:0)
您可以将第二个查询用作子查询。希望我能理解你在寻找什么。
SELECT Email, Domain, site.SiteID, site.SiteName, Status, LastLogin, up.UPID, up.UPName, trd.TRMCID, trd.TRMCName, s1.Country
FROM UserDetails as ud
INNER JOIN SiteLocation as site
on ud.SiteID = site.SiteID
INNER JOIN UltimateParent as up
on ud.UPID = up.UPID
INNER JOIN TRMCDetails as trd
on ud.TRMCID = trd.TRMCID
INNER JOIN
(
SELECT SiteID, cinfo.CountryCode, Country
From Country as cntry
INNER JOIN CountryInfo as cinfo
on cntry.CountryCode = cinfo.CountryCode
INNER JOIN SiteLocation as site2
on cntry.CountryCode = site2.CountryCode
) s1 on s1.SiteID = site.SiteID