gpt4 book ai didi

mysql - 计数函数 - Codeigniter 和 MySQL

转载 作者:行者123 更新时间:2023-11-29 12:22:00 25 4
gpt4 key购买 nike

我有一个表格如下:

表名称:品牌

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

有人可以解决我的问题吗?

最佳答案

迈克尔·伯科斯基是对的
它应该按品牌分组。

您的查询将是这样的

$this->db->select('brand, count(*) as TOTAL');
$this->db->from('brand');
$this->db->group_by('brand');
$query = $this->db->get();
return $query->result();

关于mysql - 计数函数 - Codeigniter 和 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28868962/

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