在数据库中创建virtmart视图

时间:2017-03-06 10:03:28

标签: php sql

我想在myphp中创建一个视图,我不是我正在学习的编码器, 有人能帮助我吗? 这是我的查询

YES

但我收到此错误

1060 - 重复列名'virtuemart_order_id'

有什么问题?

1 个答案:

答案 0 :(得分:1)

我认为这是由于您的select * from apef1_virtuemart_orders, apef1_virtuemart_order_items, apef1_virtuemart_order_userinfosvirtuemart_order_id列出现在多个表格中。

如果表之间存在名称冲突,则必须使用别名来确保正确创建视图。

请参阅此查询:

CREATE VIEW export AS 
    SELECT 
    avo.*, 
    avoi.order_item_sku,
    avoi.order_item_name,
    avoi.product_quantity,
    avoi.product_item_price,
    avoi.product_priceWithoutTax,
    avoi.product_tax,
    avoi.product_basePriceWithTax,
    avoi.product_discountedPriceWithoutTax,
    avoi.product_final_price,
    avoi.product_subtotal_discount,
    avoi.product_subtotal_with_tax,
    avoi.order_item_currency,
    avoi.order_status AS order_status_2,
    avoi.product_attribute,
    avoi.delivery_date AS delivery_date_2,
    avoi.created_on AS created_on_2,
    avoi.created_by AS created_by_2,
    avoi.modified_on AS modified_on_2,
    avoi.modified_by AS modified_by_2,
    avoi.locked_on AS locked_on_2,
    avoi.locked_by AS locked_by_2,
    avou.virtuemart_userinfo_id,
    avou.virtuemart_user_id,
    avou.address_type,
    avou.address_type_name,
    avou.name,
    avou.company,
    avou.title,
    avou.last_name,
    avou.first_name,
    avou.middle_name,
    avou.phone_1,
    avou.phone_2,
    avou.fax,
    avou.address_1,
    avou.address_2,
    avou.city,
    avou.virtuemart_state_id,
    avou.virtuemart_country_id,
    avou.zip,
    avou.agreed,
    avou.tos,
    avou.customer_note,
    avou.created_on AS created_on_3,
    avou.created_by AS created_by_3,
    avou.modified_on AS modified_on_3,
    avou.modified_by AS modified_by_3,
    avou.locked_on AS locked_on_3,
    avou.locked_by AS locked_by_3
    FROM
        apef1_virtuemart_orders avo, 
        apef1_virtuemart_order_items avoi, 
        apef1_virtuemart_order_userinfos avou
    WHERE avo.virtuemart_order_id = avoi.virtuemart_order_id 
    AND avo.virtuemart_order_id = avou.virtuemart_order_id

正如您所看到的,我为列created_oncreated_by等使用了别名,因为这些名称对于您的3个表来说是相同的。您可以通过调整名称来修改查询以满足您的需求。