3 番目のテーブルを追加しようとすると、少し問題が発生します。
これはテーブル構造です:
products =
id name code
5 product1 002
522 product1 002
warehouses =
id code name address city
1 store1 store1 store1 store1
warehouses_products =
id product_id warehouse_id quantity
2 5 1 -3
3 522 1 -2
4 446 1 0
データを取得する関数は次のとおりです。
$this->load->library('tables');
$this->tables
->select("products.id as productid, name, code (CASE WHEN sum(warehouses_products.quantity) Is Null THEN 0 ELSE sum(warehouses_products.quantity) END) as totalQuantity, warehouses.name");
$this->tables->from('products');
$this->tables->join('warehouses_products', 'products.id=warehouses_products.product_id', 'left');
$this->tables->join('warehouses', 'warehouses_products.id=warehouses.warehouse_id', 'left');
$this->tables->group_by("products.id");
$this->tables->unset_column('productid');
echo $this->tables->generate();
どんな助けでも大歓迎です