我有3张桌子。它们如下。
1.system_user_master
________________________
user_id
user_type
user_registeration_code
user_first_name
user_last_name
2.book_appointment
-----------------------
booking_id
booking_date
puser_id
duser_id
doctor_name
3.routine_queue_patient
----------------------
queue_id
booking_id
queue_checkin_time
puser_id
duser_id
qdoctor_name
现在我想要这样的结果
patient_registeration_code, patient_first_name, patient_last_name, booking_date, queue_checkin_time
在routine_queue_patient 中,booking_id 可以为空。我希望在routine_queue_patient 中具有booking_id 的所选医生的当前日期的患者列表有一些值或可以为空。如果booking_id 为空,那么它在查询结果中的booking_date 中显示为空,如果预订id 存在于routine_queue_patient 中,则显示为预约日期。
我已经写了查询。结果如下。
booking_date | quecheck_in_time | user_first_name | user_last_name | user_regis_code
2013-11-12 | 2013-11-12 15:50:53 | rushang | patel | rp9898 |
2013-11-12 | 2013-11-12 16:00:11 | anjana | bhatt | ab9087
rushang patel 的 booking_date 必须为 null,因为在 routine_queue_patient 中,rushang patel 的 booking_id 为 null,但我在 rushang patel 前面得到了第二条记录的 booking_date。
我写的查询如下。
SELECT DISTINCT b.booking_date
, r.queue_checkin_time
, s.user_first_name
, s.user_last_name
, s.user_registeration_code
FROM routine_queue_patient r
JOIN system_user_master s
ON r.puser_id = s.user_id
JOIN book_appointment b
ON ((b.booking_id = r.booking_id) OR r.booking_id is NULL)
AND DATE(r.queue_checkin_time) = '2013-11-12'
WHERE r.qdoctor_name = 'kashyup Nanavati'
AND DATE(b.booking_date) = '2013-11-12'
谢谢如尚