0

このクエリを codeigniter で変換する方法

select COUNT(*) 
from Retailers
where ID not In (select RetailerID from RetailerGroups)

私はこれを試しました

$this->db->where_not_in('ID',$this->db->query('select RetailerID from 
 RetailerGroups'));

 $query = $this->db->get('Retailers');

しかし、それは印刷します

Error Number: 42000

[Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ')'.

SELECT * FROM Retailers WHERE ID NOT IN ()

Filename: D:\Published\faber\core\database\DB_driver.php

Line Number: 330

助けてください

4

2 に答える 2

0

これを一度試して、

$idRs  = $this->db->select('RetailerID')->get('RetailerGroups')->result_array();
if( isset( $idRs ) && count( $idRs ) > 0 ){
    foreach( $idRs as $each ){
        $ids[]  = $each['RetailerID'];
    }
    echo "total :".$countRs    = $this->db->from('Retailers')->where_not_in('ID', $ids)->count_all_results();
}
于 2013-08-29T13:45:37.710 に答える