【问题标题】:Need help joining three table in sql using join method and concat method需要帮助使用join方法和concat方法在sql中加入三个表
【发布时间】:2017-04-18 07:45:44
【问题描述】:

以下三个表,其中最后一个表由前两个表的两列组成:

V:

我已经用 where 子句完成了问题,但无法通过 join 方法完成。 这里我使用了 where 子句:

SELECT appointmentdate,doctorname,concat(name,' ',family) AS patientname 
from appointment,doctor,patients 
WHERE doctor.doctor_id=appointment.doctor_id 
AND appointment.patient_id=patients.patient_id;

【问题讨论】:

  • 多么糟糕的问题。你没有付出任何努力来解决这个问题至少付出了一些努力来发布一个正确的问题。
  • 我确实使用 where 条件完成了问题,但无法使用 join 方法完成
  • 显示你尝试过的东西以及出了什么问题。

标签: mysql sql join concat


【解决方案1】:
SELECT a.appointmentdate,
  d.doctorname,
  p.patientname
FROM appointment a
JOIN doctors d
ON a.doctor_id = d.doctor_id
JOIN patients p
ON a.patient_id = p.patient_id;

【讨论】:

  • 所以在你的回答中a d p 指的是表名约会,医生和病人吧(抱歉刚开始学习sql)
  • 这些是表名的别名。如果我们必须在每一列前面写下整个表名,比如appointment.appointmentdate,那将非常不方便
猜你喜欢
  • 2023-04-09
  • 1970-01-01
  • 2013-09-10
  • 1970-01-01
  • 2011-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多