如何在CodeIgniter中避免单个查询中的多个联接

zbq4xfa0  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(118)

这是我密码

$this->db->select('custome_module.id, custome_module.name, min(l1.nmark_completed) as call_waiter, min(l2.nmark_completed) as bill,min(l3.nmark_completed) as tray,min(l4.nmark_completed) as ordera');
$this->db->from("custome_module");
$this->db->join('restaurant_logs as l1', 'custome_module.id = l1.nmodule_id AND l1.ntype = 1', 'left');
$this->db->join('restaurant_logs as l2', 'custome_module.id = l2.nmodule_id AND l2.ntype = 2', 'left');
$this->db->join('restaurant_logs as l3', 'custome_module.id = l3.nmodule_id AND l3.ntype = 6', 'left');
$this->db->join('restaurant_logs as l4', 'custome_module.id = l4.nmodule_id AND l4.ntype = 5', 'left');
$this->db->where('custome_module.nbranch_id', $this->data['user_session']['nid']);
$this->db->group_by('custome_module.id'); 
$this->db->get();

如何优化查询。

w9apscun

w9apscun1#

EAV是一种笨拙而低效的模式。
这将有助于提高性能 * 一些 *:

INDEX(nmodule_id, ntype)

相关问题