CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `pg2bikz3eqxbwgl5mybtxnawhccpgi`.`recalls_after_reserv` AS
select
`a`.`office_id` AS `office_id`,
`a`.`patient_id` AS `patient_id`,
`a`.`id` AS `recalls_id`,
`a`.`came_at` AS `came_at`,
`a`.`memo` AS `memo`,
`a`.`noticed_with` AS `noticed_with`,
`a`.`recall_menu` AS `recall_menu`,
`a`.`recall_type_id` AS `recall_type_id`,
`a`.`recalled_at` AS `recalled_at`,
`a`.`recalls_at` AS `recalls_at`,
`a`.`required_time` AS `required_time`,
`a`.`reservation_id` AS `bef_reservation_id`,
(case when isnull(`c`.`id`) then `d`.`id` else `c`.`id` end) AS `reservation_id`,
(case when isnull(`c`.`id`) then `d`.`starts_at` else `c`.`starts_at` end) AS **starts_at**,
(case when isnull(`c`.`id`) then `d`.`checked_in_at` else `c`.`checked_in_at` end) AS `checked_in_at`,
(case when isnull(`c`.`id`) then `d`.`created_at` else `c`.`created_at` end) AS `created_at`,
(case when isnull(`c`.`id`) then `d`.`deleted_at` else `c`.`deleted_at` end) AS `deleted_at`,
(case when isnull(`c`.`id`) then `d`.`menu_id` else `c`.`menu_id` end) AS `next_menu_id`,
(case when isnull(`c`.`id`) then `d`.`cancel_type` else `c`.`cancel_type` end) AS `cancel_type`,
`a`.`menu_id` AS `menu_id`,
`a`.`menu2_id` AS `menu2_id`,
`a`.`menu3_id` AS `menu3_id`,
(case when isnull(`c`.`id`) then NULL else `a`.`created_reservation_id` end) AS `created_reservation_id`,
`z`.`datetime_disp` AS `datetime_disp`
from (
((`pg2bikz3eqxbwgl5mybtxnawhccpgi`.`recalls` `a`
left join `pg2bikz3eqxbwgl5mybtxnawhccpgi`.**reservations** `c` on(((`a`.`created_reservation_id` = `c`.`id`) and (isnull(`c`.`deleted_at`)
or ((`c`.`deleted_at` is not null) and (`c`.`cancel_type` = 'patient'))))))
left join `pg2bikz3eqxbwgl5mybtxnawhccpgi`.`recalls_after_start_at` `z` on((`a`.`id` = `z`.`recalls_id`)))
left join `pg2bikz3eqxbwgl5mybtxnawhccpgi`.**reservations** `d` on(((`z`.`office_id` = `d`.`office_id`)
and (`z`.`patient_id` = `d`.`patient_id`)
and (`z`.`starts_at` = `d`.`starts_at`)
and (isnull(`z`.`menu_id`) or (`z`.`menu_id` = `d`.`menu_id`))
and (isnull(`d`.`deleted_at`) or ((`d`.`deleted_at` is not null) and (`d`.`cancel_type` = 'patient')))))
)
where isnull(`a`.`deleted_at`);
在此视图表中,预留表有两个名称:c和d。 这就是为什么 ?有什么不同 ?如果你认为它有两个广泛的答案,你能给我一些链接来学习这些SQL吗?