doujia2090 2019-01-22 07:03
浏览 73

内部联接和按日期过滤不工作抛出完整性约束违规错误 - Magento 1

I am trying to make an inner join on two tables to get data. and it worked however when I search to get date from the table. I get an error saying

Integrity constraint violation: 1052 Column 'created_at' in where clause 
is ambiguous, query was: SELECT COUNT(*) FROM `sales_flat_order` AS 
`main_table`
INNER JOIN `sales_flat_order_item` ON main_table.store_id = 
sales_flat_order_item.store_id WHERE (`created_at` >= '2017-04-01'

This is my code

    $collection = Mage::getModel('sales/order')->getCollection();

    $collection->addFieldToFilter('created_at');
    $collection->getSelect()->join("sales_flat_order_item", 
    "main_table.store_id = sales_flat_order_item.store_id", 
    array('name','sku','order_id','quantity'));
  • 写回答

2条回答 默认 最新

  • duancenxiao0482 2019-01-22 10:30
    关注

    You can try something like this

    $collection = Mage::getModel('sales/order')->getCollection();
    $collection->addFieldToFilter('main_table.created_at', '2017-04-01');
    $collection->getSelect()->join("sales_flat_order_item",
        "main_table.store_id = sales_flat_order_item.store_id",
        array('name','sku','order_id','qty_ordered'));
    

    But your join looks weird maybe it would be better to use sales_flat_order.entity_id = sales_flat_order_item.order_id then store_id

    What exactly do you try to get by that select?

    Please, describe your task.

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计