gpt4 book ai didi

php - 带有内连接的 Codeigniter 子查询

转载 作者:行者123 更新时间:2023-11-29 15:14:41 26 4
gpt4 key购买 nike

我很难将 MySQL 查询转换为 Codeigniter 查询生成器。我无法与同一张表进行内部联接。就像我的 mySQL 查询一样。它正在 mySQL 上运行。这是我的查询:

$sql = "SELECT answers.* FROM answers INNER JOIN
(SELECT * FROM
(SELECT employee_id as test_employee_id, created_on as test_created_on FROM answers) as test
GROUP BY test.test_employee_id)
AS test on (test.test_employee_id = answers.employee_id AND test.test_created_on = answers.created_on)
ORDER BY answers.created_on DESC";

你们能帮我解决这个问题吗?我正在尝试将其转换为 Codeigniter 查询。

最佳答案

试试这个:

$this->db->select('answers.*');    
$this->db->from('answers');
$this->db->join('(SELECT * FROM
(SELECT employee_id as test_employee_id, created_on as test_created_on FROM answers) as test1
GROUP BY test1.test_employee_id)
AS test', 'test.test_employee_id = answers.employee_id AND test.test_created_on = answers.created_on');
$this->db->order_by("answers.created_on", "desc");
$query = $this->db->get();
return $query->result();

关于php - 带有内连接的 Codeigniter 子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59807687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com