私は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 を null にすることができます。routine_queue_patient にいる選択した医師の現在の日付の患者のリストで、booking_id に何らかの値があるか、null にすることができます。booking_id が null の場合、クエリ結果の booking_date に null が表示され、予約の場合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
ルシャン・パテルのbooking_dateはnullである必要があります。ルーチン_キュー_患者の場合、ルシャン・パテルのbooking_idはnullですが、ルシャン・パテルの前にある2番目のレコードの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'
ありがとう