douwen3083
2017-09-08 02:34
浏览 58
已采纳

CodeIgniter Active记录子查询中的位置

How do I write where_in statement a subquery using codeigniter active records ?

$query = $this->db->query("SELECT SUM(a.transaction_payment_amount) FROM 
         transaction_payment a WHERE a.transaction_link IN 
         (SELECT transaction_link FROM transaction WHERE transaction_type = '22'");
$result = $query->result();

Now how to convert the above query into CI active records ?

I have tried:

$this->db->select("SUM(a.transaction_payment_amount)");
$this->db->from('transaction_payment a');
$this->db->where_in('a.transaction_link', "SELECT transaction_link from transaction WHERE transaction_type = '22'");
$query = $this->db->get();
$result = $query->result();

But it doesn't work.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • dongwuxie5112 2017-09-08 05:05
    最佳回答

    Try This

    $this->db->where_in('a.transaction_link', "SELECT transaction_link from transaction WHERE transaction_type = '22'",false);
    

    if you use false then it will remove single quotes from where_in condition

    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题