2

我有以下表格:

1. tbPatientEpisode (
    EpisodeIDP
    EpisodeNumber
    DoctorIDF
    PatientIDF
)

2. tbPatient (
    PatientIDP
    CitizenIDF
)

3. tbDoctor(
    DoctorIDP
    CitizenIDF
)

4. tbCitizen(
    CitizenIDP
    CitizenName
    City
    ContactNo
)

我想查询 tbPatientEpisode 表,连续获取 DoctorName 和 PatientName,但 PatientIDF 和 DoctorIDF 指向 tbCitizen。所以请帮助加入 tbCitizen 表两次。

4

1 回答 1

1

试试这个它对你很好,

    Select pe.*, c1.CitizenName as PatientName, c2.CitizenName as DoctorName 
    from tbPatientEpisode pe
    join tbPatient p on pe.PatientIDF = p.PatientIDP
    join tbDoctor d on pe.DoctorIDF = d.DoctorIDP
    join tbCitizen c1 on p.CitizenIDF = c1.CitizenIDP
    join tbCitizen c2 on d.CitizenIDF = c2.CitizenIDP
于 2013-05-29T08:21:38.227 回答