public function getDebits(){
$data = array(
'debit_side.account_code DebitCode',
'group_concat(distinct accounts.name) as DebitAccount',
'group_concat(debit_side.amount) as DebitAmount',
'group_concat(transaction_info.voucher_date) as DebitVoucherDate'
);
$this->db->select($data);
$this->db->from('accounts');
$this->db->join('credit_side','accounts.code = credit_side.account_code','left');
$this->db->join('debit_side','debit_side.transaction_id_dr = credit_side.transaction_id_cr','left');
$this->db->join('transaction_info','transaction_info.transaction_id = credit_side.transaction_id_cr','left');
$this->db->group_by('debit_side.account_code');
$this->db->order_by('debit_side.account_code','ASC');
$query = $this->db->get();
return $query->result_array();
}
public function getCredits()
{
$data = array(
'credit_side.account_code CreditCode',
'group_concat(distinct accounts.name) as CreditAccount',
'group_concat(credit_side.amount) as CreditAmount',
'group_concat(transaction_info.voucher_date) as CreditVoucherDate'
);
$this->db->select($data);
$this->db->from('accounts');
$this->db->join('debit_side','accounts.code = debit_side.account_code','left');
$this->db->join('credit_side','debit_side.transaction_id_dr = credit_side.transaction_id_cr','left');
$this->db->join('transaction_info','transaction_info.transaction_id = credit_side.transaction_id_cr','left');
$this->db->group_by('credit_side.account_code');
$this->db->order_by('credit_side.account_code','ASC');
$query = $this->db->get();
return $query->result_array();
}
देर से उत्तर देने के लिए क्षमा करें, लेकिन कुछ भी करने से पहले यह एकदम सही चीज है जिसे आप परीक्षण करना चाहते हैं। मैं इसके लिए एक दृश्य फ़ाइल बनाना चाहता था, लेकिन यह जटिल लगता है और इसमें अधिक समय लगता है जो इस समय मैं झील पर जाता हूं
संपादित
यह समाधान आपको देखने पर रैकिंग कर सकता है क्योंकि मैंने इसका परीक्षण किया है कि मैंने कभी भी इन दो प्रश्नों को संयोजित करने का प्रयास किया और सफल रहा। क्वेरी कुछ जटिल लग सकती है लेकिन यह सही परिणाम ला रही है। यह यहाँ है
$data = array(
'debit_side.account_code Code',
'group_concat(distinct accounts.name) as DebitAccount',
'group_concat(debit_side.amount) as DebitAmount',
'group_concat(transaction_info.voucher_date) as DebitVoucherDate',
'(SELECT group_concat(distinct accounts.name) as CreditAccount FROM (accounts)
left JOIN debit_side ON accounts.code = debit_side.account_code
left JOIN credit_side ON debit_side.transaction_id_dr = credit_side.transaction_id_cr
left JOIN transaction_info ON transaction_info.transaction_id = credit_side.transaction_id_cr
group by credit_side.account_code
having credit_side.account_code = `Code`) as CreditAccount',
'(SELECT group_concat(credit_side.amount) as CreditAmount FROM (accounts)
left JOIN debit_side ON accounts.code = debit_side.account_code
left JOIN credit_side ON debit_side.transaction_id_dr = credit_side.transaction_id_cr
left JOIN transaction_info ON transaction_info.transaction_id = credit_side.transaction_id_cr
group by credit_side.account_code
having credit_side.account_code = `Code`) as CreditAmount',
'(SELECT group_concat(transaction_info.voucher_date) as CreditVoucherDate FROM (accounts)
left JOIN debit_side ON accounts.code = debit_side.account_code
left JOIN credit_side ON debit_side.transaction_id_dr = credit_side.transaction_id_cr
left JOIN transaction_info ON transaction_info.transaction_id = credit_side.transaction_id_cr
group by credit_side.account_code
having credit_side.account_code = `Code`) as CreditVoucherDate'
);
$this->db->select($data);
$this->db->from('accounts');
$this->db->join('credit_side','accounts.code = credit_side.account_code','left');
$this->db->join('debit_side','debit_side.transaction_id_dr = credit_side.transaction_id_cr','left');
$this->db->join('transaction_info','transaction_info.transaction_id = credit_side.transaction_id_cr','left');
$this->db->group_by('debit_side.account_code');
$this->db->order_by('debit_side.account_code','ASC');
$query = $this->db->get();
return $query->result_array();
हालाँकि यह क्वेरी ठीक काम करती है लेकिन यहाँ इस क्वेरी का एक संशोधित और अनुकूलित संस्करण है, मैंने वास्तव में इस क्वेरी से चीजें सीखी हैं, आपको इस पर भी एक नज़र डालनी चाहिए
क्वेरी में समूह का अजीब व्यवहार जिसे अनुकूलित करने की आवश्यकता है