[英]Code igniter and 'twice' group by
I have following query in CodeIgniter: 我在CodeIgniter中有以下查询:
$this->db
->select($this->vehicle_table.'.idvehicle, mark, type')
->group_by('mark')
->order_by('vehicles.mark', "desc")
->get($this->vehicle_table)
->result_array();
In my table I have record like: 在我的表中,我记录如下:
type: auto mark: VW 类型: 自动标记: 大众
and 和
type: bus mark: VW 类型: 公交标志: 大众
This query works fine, but I'm getting only record (for VW) where type: auto , this query is ignoring type: bus 此查询工作正常,但我只获得类型为: auto的记录(针对大众),此查询忽略了类型: bus
I have to "group by" two columns, right? 我必须“分组”两列,对吗?
How should I write query to reach records separately by type and mark ? 如何编写查询以按类型和标记分别到达记录?
edit 编辑
Solved, i added "->group_by('type')" before "->group_by('mark')". 解决后,我在“-> group_by('mark')”之前添加了“-> group_by('type')”。
Sory for that question, it was easy :) 对不起,这个问题很简单:)
Yes, you need to group by two columns. 是的,您需要按两列分组。
In CI's Active Records, you just make it an array: 在CI的Active Record中,只需将其设置为数组即可:
...
->group_by(array('mark', 'type'))
...
This will produce: GROUP BY mark, type
这将产生:
GROUP BY mark, type
See the docs here: http://ellislab.com/codeigniter/user-guide/database/active_record.html 请参阅此处的文档: http : //ellislab.com/codeigniter/user-guide/database/active_record.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.