중복 속성을 하나의 행을 확장하는 부품 :가입 여러 테이블 내가 함께 가입해야 내가 5 개 테이블을했습니다
$ProductsTable = new Products();
$select = $ProductsTable->select();
$select->from(array('P' => 'products'), array('product_id', 'product_name'));
$select->setIntegrityCheck(false);
$select->joinLeft(array('DI' => 'directsells_items'), 'DI.product_id = P.product_id', array('item_price', 'item_discount', 'qty'));
$select->joinLeft(array('D' => 'directsells'), 'DI.directsell_id = D.directsell_id', array('directsell_number AS invoice_number', 'directsell_date AS invoice_date', 'invoice_status'));
$select->where('DATE(D.directsell_date) BETWEEN "'. date('Y-m-d', strtotime($from_date)) .'" AND "'. date('Y-m-d', strtotime($to_date)) .'"');
$select->where('D.invoice_status <> "Canceled"');
$select->joinLeft(array('OI' => 'order_items'), 'OI.product_id = P.product_id', array('item_price', 'item_discount', 'qty'));
$select->joinLeft(array('O' => 'orders'), 'OI.order_id = O.order_id', array('order_number AS invoice_number', 'order_date AS invoice_date'
,'IF(`order_status` = "10", "Returned", "Active") AS invoice_status'
));
$select->where('DATE(O.order_date) BETWEEN "'. date('Y-m-d', strtotime($from_date)) .'" AND "'. date('Y-m-d', strtotime($to_date)) .'"');
$select->where('O.order_status <> "0"');
$select->where('P.product_id = '. $product_id);
: 나는 젠드 프레임 워크를 사용하고
products:
- product_id
orders
- order_id
order_items
- item_id
- order_id
- product_id
directsells
- directsell_id
directsell_items
- item_id
- directsell_id
- product_id
을, 여기에 내 코드입니다 directsell_items
에서
그리고 내가 가지고있는 order_items
1 개 단일 항목 :내 쿼리의 결과로 얻고 무엇
는 directsell_items
에서 두 항목과 같이, order_item
에 하나 병합 :
나는 모든 것이 분명하다 바랍니다. 가입에 문제가 있다는 것을 알고 있지만, 알아 내지 못했습니다.
것은 구별 할 수있는 중복 컬럼 별칭을 부여합니다. – Barmar
하지만 여러 개의 동일한 개체 (이 경우 3 행이어야 함)로 결과를 얻어야 쉽게 작업 할 수 있습니다. – MAZux
@Barmar 그게 가능합니까? – MAZux