【发布时间】:2014-04-03 13:12:59
【问题描述】:
这段代码在mysql运行命令中完美运行
SELECT employeeCode
FROM employee_details
WHERE employeeCode
IN (
SELECT DISTINCT (employeeCode) FROM quiz_answer_detailsWHERE submitTime
IN (SELECT MIN( submitTime ) FROM quiz_answer_details WHERE quizId
IN (SELECT id FROM quiz_details WHERE uploadtime = '2014-04-03')
AND answer IN (SELECT answer FROM quiz_details WHERE uploadtime = '2014-04-03'))
)
但我想在我的 codeigniter 上使用此代码,但它不起作用。
我的codeigniter查询代码是
$this->db->select('employeeCode');
$this->db->from('employee_details');
$this->db->where_in('employeeCode');
$this->db->select('DISTINCT(employeeCode)');
$this->db->from('quiz_answer_details');
$this->db->where_in('submitTime');
$this->db->select('min(submitTime)');
$this->db->from('quiz_answer_details');
$this->db->where_in('quizId');
$this->db->select('id');
$this->db->from('quiz_details');
$this->db->where('uploadtime',"2014-04-03");
$this->db->where_in('answer');
$this->db->select('answer');
$this->db->from('quiz_details');
$this->db->where('uploadtime',"2014-04-03");
$query=$this->db->get();
print_r($query);
if($query->num_rows>=1)
{
return $query;
}
else
{
return false;
}
有什么问题请帮帮我
【问题讨论】:
-
你使用的 CodeIgniter 是什么版本的?
-
我见过很多,但 Active Records 是这样使用的……从来没有。
-
如果 CodeIgniter 3 - 使用
get_compiled_select(),如果 CodeIgniter 2 - 请参阅 Is there a function like _compile_select or get_compiled_select()? 以及有关使用子查询生成查询的相关问题。
标签: php mysql codeigniter