简体   繁体   English

嗨,我在这个查询中做错了什么?

[英]Hi what i am doing wrong with this query?

I want to select the income amount from income table, update the total income and subtract the income from the total income.我想从收入表中选择收入金额,更新总收入并从总收入中减去收入。 Then delete the row.然后删除该行。

public function delete($id)
{ 
    $this->db->get('income');
    $this->db->select('income_amount');
    $this->db->query('update total_income set amount=amount-'.$this->db->select('income_amount'));

    $this->db->where('income_id', $id);
    $this->db->delete('income');    
}

Unless I have misunderstood your question, you want to do the following :除非我误解了您的问题,否则您要执行以下操作:

  1. Select income_amount from the income table :income表中选择income_amount

     $this->db->select('income_amount'); $query = $this->db->get('income'); $row = $query->row(); if (isset($row)) { $income_amount = $row->income_amount; }
  2. Update the total_income table by substracting $income_amount from all the amount values of the table :通过从表的所有amount值中减去$income_amount来更新total_income表:

     $this->db->set('amount', 'amount-'.$income_amount); $this->db->update('total_income');
  3. Delete the row identified by $id from the income table :income表中删除$id标识的行:

     $this->db->delete('income', array('income_id' => $id));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM