Mysql 仅当字段不为空时,Codeigniter分组依据
我有以下疑问:Mysql 仅当字段不为空时,Codeigniter分组依据,mysql,codeigniter,Mysql,Codeigniter,我有以下疑问: $this->db->select('SUM(cost_price) AS cost_price,SUM(cost_price) AS total,employees.username AS staff_name'); $this->db->from('items'); $this->db->join('customers', 'customers.person_id = items.customer_id');
$this->db->select('SUM(cost_price) AS cost_price,SUM(cost_price) AS total,employees.username AS staff_name');
$this->db->from('items');
$this->db->join('customers', 'customers.person_id = items.customer_id');
$this->db->join('employees', 'employees.person_id = items.staff_id');
$this->db->join('people', 'people.person_id = customers.person_id');
$this->db->group_by('items.is_serialized');
在items表中,我有一个名为is_serialized的字段,我想对is_serialized字段中具有值的所有行进行分组,但不分组。如果该行为空,是否可以使用我的查询进行分组?将要分组的条件放置在is_serialized的下面
$this->db->where('items.is_serialized IS NOT NULL');
在GROUPBY子句中使用“CASE”函数仅检查NOTNULL值
例如:
我还需要结果中的is_序列化空行。请共享每个表的列(所有表的表结构)以及哪个字段不应为空?
$this->db->group_by("CASE WHEN items.is_serialized IS NOT NULL THEN items.is_serialized END",FALSE);