我有两个工作 MySQL 视图:
第一个视图从表中选择所有行,portfolio
其中 id 也在表mural
中。
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `view_mural` AS
select
`portfolio`.`id` AS `id`,
`portfolio`.`customer_id` AS `customer_id`,
`portfolio`.`location_id` AS `location_id`,
`portfolio`.`title_text_id` AS `title_text_id`,
`portfolio`.`description_text_id` AS `description_text_id`,
`portfolio`.`started` AS `started`,
`portfolio`.`finished` AS `finished`,
from
`portfolio`
where
`portfolio`.`id` in (select
`mural`.`portfolio_id`
from
`mural`) WITH CASCADED CHECK OPTION
第二个视图从两个表中选择行:portfolio
和mural
。
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `view_mural` AS
select
`portfolio`.`id` AS `id`,
`portfolio`.`customer_id` AS `customer_id`,
`portfolio`.`location_id` AS `location_id`,
`portfolio`.`title_text_id` AS `title_text_id`,
`portfolio`.`description_text_id` AS `description_text_id`,
`portfolio`.`started` AS `started`,
`portfolio`.`finished` AS `finished`,
(select
`mural`.`width`
from
`mural`
where
`mural`.`portfolio_id`=`portfolio`.`id`) AS `mup`
from
`portfolio`
我不知道如何将这些组合到一个视图中,以选择表,其中包含两个表中的列,其中包含表组合中的行,其中 id 也在表壁画中。
当我添加:
where
`portfolio`.`id` in (select
`mural`.`portfolio_id`
from
`mural`) WITH CASCADED CHECK OPTION
在我的第二个视图的最后,它向我显示了一个错误:
Apply changes to view_mural Error 1368: CHECK OPTION on non-updatable view 'view_mural' SQL Statement: CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = `root`@`localhost` SQL SECURITY DEFINER VIEW `view_mural` AS select `portfolio`.`id` AS `id`, `portfolio`.`customer_id` AS `customer_id`, `portfolio`.`location_id` AS `location_id`, `portfolio`.`title_text_id` AS `title_text_id`, `portfolio`.`description_text_id` AS `description_text_id`, `portfolio`.`started` AS `started`, `portfolio`.`finished` AS `finished`, (select `mural`.`width` from `mural` where `mural`.`portfolio_id`=`portfolio`.`id`) AS `mup` from `portfolio` where `portfolio`.`id` in (select `mural`.`portfolio_id` from `mural`) WITH CASCADED CHECK OPTION Error when running failback script. Details follow. Error 1050: Table 'view_mural' already exists SQL Statement: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_mural` AS select `portfolio`.`id` AS `id`,`portfolio`.`customer_id` AS `customer_id`,`portfolio`.`location_id` AS `location_id`,`portfolio`.`title_text_id` AS `title_text_id`,`portfolio`.`description_text_id` AS `description_text_id`,`portfolio`.`started` AS `started`,`portfolio`.`finished` AS `finished`,(select `mural`.`width` from `mural` where ((`mural`.`portfolio_id` = `portfolio`.`id`) and `portfolio`.`id` in (select `mural`.`portfolio_id` from `mural`))) AS `mup` from `portfolio`
有人可以指出我该怎么做吗?