我已经定义了可以正常运行的查询:
SELECT `a`.`id`,
`a`.`fld_tribunal` AS `fld_tribunal`,
`a`.`fld_date` AS `fld_date`,
`a`.`fld_juge` AS `fld_juge`,
`a`.`fld_representant_prefecture` AS `fld_representant_prefecture`,
`a`.`fld_interpretes` AS `fld_interpretes`,
`a`.`fld_nombre_policiers` AS `fld_nombre_policiers`,
`a`.`fld_retenus_menottes` AS `fld_retenus_menottes`,
`a`.`fld_representants_cdv` AS `fld_representants_cdv`,
`a`.`fld_public` AS `fld_public`,
`a`.`fld_duree_audience` AS `fld_duree_audience`,
`a`.`fld_duree_delibere` AS `fld_duree_delibere`
FROM `cr_tribunaux` `a`
INNER JOIN `list_records` `r`
ON ((`r`.`form_id` = 8) AND (`r`.`record_id` = `a`.`id`))
INNER JOIN `list_states` `s`
ON ((`s`.`id` = `r`.`state_id`) AND (`s`.`form_id` = `r`.`form_id`) )
WHERE `s`.`id`=74 OR `s`.`id`=75
ORDER BY `a`.`fld_date` ASC
但是当我尝试使用phpMyadmin从中创建视图时,出现错误:
Notice in ./libraries/SystemDatabase.php#52
Undefined index: column_info
Backtrace
./view_create.php#140: PMA\libraries\SystemDatabase->getExistingTransformationData(string 'maindb')
当我删除INNER JOIN
语句时,该视图会很好地创建,因此,在我使用的语法中或在JOIN所针对的表中都必须有某些内容。
我尝试了不同的括号组合,但没有帮助。
三个相关表的表创建代码为:
CREATE TABLE `cr_tribunaux` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`storage_id` int(11) NOT NULL DEFAULT '4',
`user_id` int(11) NOT NULL DEFAULT '0',
`created` datetime NOT NULL DEFAULT '2018-07-10 09:51:32',
`created_by` varchar(255) NOT NULL DEFAULT '',
`modified_user_id` int(11) NOT NULL DEFAULT '0',
`modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified_by` varchar(255) NOT NULL DEFAULT '',
`fld_tribunal` text NOT NULL,
`fld_juge` text NOT NULL,
`fld_date` text NOT NULL,
`fld_representant_prefecture` text NOT NULL,
`fld_nombre_policiers` text NOT NULL,
`fld_retenus_menottes` text,
`fld_public` text NOT NULL,
`fld_representants_cdv` text NOT NULL,
`fld_duree_delibere` text,
`fld_compte_rendu` text NOT NULL,
`fld_remarques` text NOT NULL,
`fld_interpretes` text NOT NULL,
`fld_duree_audience` text NOT NULL,
`fld_retenus_menottes_detail` text NOT NULL,
PRIMARY KEY (`id`),
KEY `storage_id` (`storage_id`),
KEY `user_id` (`user_id`),
KEY `created` (`created`),
KEY `modified_user_id` (`modified_user_id`),
KEY `modified` (`modified`)
) ENGINE=MyISAM AUTO_INCREMENT=747 DEFAULT CHARSET=utf8```
CREATE TABLE `list_states` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`form_id` int(11) NOT NULL DEFAULT '0',
`title` varchar(255) NOT NULL DEFAULT '',
`color` varchar(255) NOT NULL DEFAULT '',
`action` varchar(255) NOT NULL DEFAULT '',
`published` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=221 DEFAULT CHARSET=utf8
CREATE TABLE `list_records` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`form_id` int(11) NOT NULL DEFAULT '0',
`record_id` bigint(20) NOT NULL DEFAULT '0',
`state_id` int(11) NOT NULL DEFAULT '0',
`reference_id` int(11) NOT NULL DEFAULT '0',
`published` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `form_id` (`form_id`,`record_id`,`state_id`)
) ENGINE=MyISAM AUTO_INCREMENT=811 DEFAULT CHARSET=utf8
答案 0 :(得分:0)
要创建视图,可以使用以下代码
CREATE VIEW sample_test AS
SELECT `a`.`id`,
`a`.`fld_tribunal` AS `fld_tribunal`,
`a`.`fld_date` AS `fld_date`,
`a`.`fld_juge` AS `fld_juge`,
`a`.`fld_representant_prefecture` AS `fld_representant_prefecture`,
`a`.`fld_interpretes` AS `fld_interpretes`,
`a`.`fld_nombre_policiers` AS `fld_nombre_policiers`,
`a`.`fld_retenus_menottes` AS `fld_retenus_menottes`,
`a`.`fld_representants_cdv` AS `fld_representants_cdv`,
`a`.`fld_public` AS `fld_public`,
`a`.`fld_duree_audience` AS `fld_duree_audience`,
`a`.`fld_duree_delibere` AS `fld_duree_delibere`
FROM `cr_tribunaux` `a`
INNER JOIN `list_records` `r`
ON ((`r`.`form_id` = 8) AND (`r`.`record_id` = `a`.`id`))
INNER JOIN `list_states` `s`
ON ((`s`.`id` = `r`.`state_id`) AND (`s`.`form_id` = `r`.`form_id`) )
WHERE `s`.`id`=74 OR `s`.`id`=75
ORDER BY `a`.`fld_date` ASC;
即使尝试执行此操作后仍然出现错误,也一定是PHPMyadmin存在问题。您可以根据您的操作系统尝试使用任何其他客户端(例如mysqlworkbench,sqlyog,HeidiSql)来创建此视图。
答案 1 :(得分:0)
我找到了解决该问题的方法,可以很好地满足我的需求。 我试图创建的视图从cr_tribunaux表中选择“应用程序有效”记录。该视图后来被连接到辅助表,从而产生包含所有所需列的“有效”记录的列表。 然后,我创建了一个没有JOIN的简单视图,并带有“ list_records”和“ list_states”表,在第二个视图中,我介绍了记录验证功能。
奇怪的是,Mysql并没有抱怨这个新视图,所以现在我有了一个最终的复合视图,该视图给出了我一直在寻找的结果:-)
我想Mysql需要一点“帮助”来了解如何做我想做的事。
虽然这解决了我的问题,但并没有给出导致错误的根本问题的答案。
感谢您的帮助。