Codeigniter 4 中的子查询条件

问题描述 投票:0回答:1

知道如何将下面的查询转换为 Codeigniter 吗?

select agency from agency where agency not in (SELECT agency FROM trip where trip_type = 'local trip' group by trip_type, agency having count(agency)=(select count(*) from role));

尝试过但失败了。请帮忙

mysql codeigniter
1个回答
0
投票
$this->db->select('agency');
$this->db->from('agency');
$this->db->where_not_in('agency', function($query) {
$query->select('agency')->from('trip')->where('trip_type', 'local trip')->group_by(['trip_type', 'agency'])->having('count(agency)', '(SELECT count(*) FROM role)', FALSE);
}, NULL, FALSE);
$query = $this->db->get();
© www.soinside.com 2019 - 2024. All rights reserved.