计数函数 - Codeigniter 和 MySQL
Count Function - Codeigniter and MySQL
我有一个 table 如下:
table 姓名:品牌
id | brand
1 | UNIQLO
2 | PDI
3 | PDI
4 | H&M
5 | UNIQLO
我需要的结果是:
PDI x 2
UNIQLO x 2
H&M x 1
我已经试过了:
$this->db->select('brand, count(*) as TOTAL');
$this->db->from('brand');
$this->db->group_by('id');
$query = $this->db->get();
return $query->result();
但我的输出是uniqlopdiuniqlopdiH&Muniqlo
。
谁能解决我的问题?
Michael Berkowski 是对的
它应该按品牌分组。
您的查询将是这样的
$this->db->select('brand, count(*) as TOTAL');
$this->db->from('brand');
$this->db->group_by('brand');
$query = $this->db->get();
return $query->result();
我有一个 table 如下:
table 姓名:品牌
id | brand
1 | UNIQLO
2 | PDI
3 | PDI
4 | H&M
5 | UNIQLO
我需要的结果是:
PDI x 2
UNIQLO x 2
H&M x 1
我已经试过了:
$this->db->select('brand, count(*) as TOTAL');
$this->db->from('brand');
$this->db->group_by('id');
$query = $this->db->get();
return $query->result();
但我的输出是uniqlopdiuniqlopdiH&Muniqlo
。
谁能解决我的问题?
Michael Berkowski 是对的
它应该按品牌分组。
您的查询将是这样的
$this->db->select('brand, count(*) as TOTAL');
$this->db->from('brand');
$this->db->group_by('brand');
$query = $this->db->get();
return $query->result();