0
我的數據庫中有三個表。 首先表 - insurance_policy,二單insurance_customer &第三單insurance_paymentsCodeigniter加入多個表和總和
我試圖與特定的日期範圍,從策略表中的數據,同時試圖拉從客戶表中的客戶信息&終於設法得到該政策的付款信息。
這裏是那麼遠
$this->db->select('*');
$this->db->from('insurance_policy');
$this->db->join('insurance_customer', 'insurance_customer.customer_id = insurance_policy.Customer_ID', 'left');
$this->db->join('insurance_payments', 'insurance_payments.Policy_Number = insurance_policy.Policy_ID', 'left');
$this->db->where('insurance_policy.Payment_Date >=', $from);
$this->db->where('insurance_policy.Payment_Date <=', $to);
$query = $this->db->get();
return $query->result_array();
我想,而不是返回的所有記錄,從支付表中獲取金額列的總和,代碼。由於支付數據可以是多個,並且具有相同的政策ID,因此我可以得到多個支付數據結果,如下面的結果。相反,我試圖根據策略ID獲得一個結果(由於該策略ID的多次付款而不重複)&該策略的付款表的金額總和。
在此先感謝。
Array
(
[0] => Array
(
[Policy_ID] => 26
[Policy] => 1234
[Customer_ID] => 30
[Effective_Date] => 06/08/2016
[Expiration_Date] => 06/08/2017
[Insurer] => Lorem
[Billing] => Lorem
[Agent] => Lorem
[Notes] => Lorem
[Mail_Date] =>
[Callback_Date] =>
[Contact_Date] =>
[Type] => Lorem
[Policy_Total] => 140
[Commission_Amount] => 0
[Brokerage_Fee] => 0
[Insurance_Price] => 140
[Payment_Date] => 06/08/2016
[Cancellation_Date] =>
[Paid_in_Full] => 0
[customer_id] => 30
[First_Name] => Lorem
[Last_Name] => Lorem
[Company_Name] => Lorem
[Company_Type] => Lorem
[EIN_Number] =>
[Fee_License] => 1234
[Address] => Lorem
[City] => Lorem
[State] => CA
[Zipcode] => 12345
[Phone] => 123-456-7890
[Alt_Number] =>
[Fax_Number] =>
[Email] => [email protected]
[id] => 8
[Policy_Number] => 26
[Date] => 08/16/2017
[Amount] => 400
[status] => 1
)
[1] => Array
(
[Policy_ID] => 26
[Policy] => 1234
[Customer_ID] => 30
[Effective_Date] => 06/08/2016
[Expiration_Date] => 06/08/2017
[Insurer] => Lorem
[Billing] => Lorem
[Agent] => Lorem
[Notes] =>
[Mail_Date] =>
[Callback_Date] =>
[Contact_Date] =>
[Type] => Lorem
[Policy_Total] => 140
[Commission_Amount] => 0
[Brokerage_Fee] => 0
[Insurance_Price] => 140
[Payment_Date] => 06/08/2016
[Cancellation_Date] =>
[Paid_in_Full] => 0
[customer_id] => 30
[First_Name] => Art
[Last_Name] => Lorem
[Company_Name] => Lorem
[Company_Type] => Lorem
[EIN_Number] =>
[Fee_License] => 55555
[Address] => Lorem
[City] => Lorem
[State] => CA
[Zipcode] => 12345
[Phone] => 333-444-5555
[Alt_Number] =>
[Fax_Number] =>
[Email] => [email protected]
[id] => 4
[Policy_Number] => 26
[Date] => 08/15/2017
[Amount] => 200.10
[status] => 1
)
)