我有3張桌子,一張用於研究,另外一張則是旅行和國家。研究。 Study
表包含StudyID,StartDate,EndDate,CountryID
並將StudyID
設爲primary key
。如何加入3張表
Travel
表包含TravelID,StudyID,CountryID,TravelStartDate,TravelEndDate
,TravelID
爲Primary key
和StudyID
爲Foreign key
。
Country
表包含CountryID,CountryCode,CountryName, CountryID
作爲primary key
。
我想CountryName
像"CountryCode+' - '+CountryName as CountryName".
我有以下查詢:
SELECT
Study.CountryID
,Travel.CountryID
,StartDate
,EndDate
,TravelStartDate,TravelEndDate,
, CountryCode+' - '+CountryName as CountryName,
FROM dbo.Study left join dbo.Countries
on
Study.CountryID=Countries.CountryID
left join Travel
on
Travel.StudyID=Study.StudyID
我想顯示CountryName
爲Travel
和Study
。我如何顯示一個國家的旅行和一個用於學習?