可以像这样创建表:
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
DROP TABLE IF EXISTS {$this->getTable('sample_table')};
CREATE TABLE IF NOT EXISTS {$this -> getTable ('sample_table')} (`id` INT (10) UNSIGNED NOT NULL COMMENT 'primary key', `name` INT (10) NULL COMMENT 'name')
");
$installer->endSetup();
但我不知道如何以上述方式创建数据库视图,如下所示:
CREATE VIEW SAMPLE_VIEW AS
SELECT A.NAME, B.NAME FROM TABLE_A A
INNER JOIN TABLE_B B ON A.FIELD_1 = B.FIELD_1;
有什么办法吗?
答案 0 :(得分:0)
我没有测试过以下代码,但它可能对您有所帮助。
<?php
$installer = $this;
$installer->startSetup();
// This will work fine
$installer->run("CREATE VIEW SAMPLE_VIEW AS SELECT A.entity_id, A.type_id, B.path
FROM `catalog_product_entity` A
INNER JOIN `catalog_category_entity` B ON A.entity_id = B.entity_type_id");
// try the below code if you have already model design
$installer->run("CREATE VIEW SAMPLE_VIEW AS SELECT A.entity_id, A.type_id, B.path
FROM {$this->getTable('your_custom_table')} A
INNER JOIN {$this->getTable('your_custom_table')} B ON A.entity_id = B.entity_type_id");
$installer->endSetup();
如果您有任何疑问,请与我们联系。
感谢。