我在cakephp中有一个表,包含box_id和quantity列。 如果我运行此查询:
$a = $this->Order->query('SELECT SUM(quantity) AS q FROM order_boxes GROUP BY box_id ');
我总是得到一个奇怪的数组:
Array
(
[0] => Array
(
[0] => Array
(
[q] => 242
)
)
[1] => Array
(
[0] => Array
(
[q] => 22
)
)
)
我会得到一个简单的表(就像SQL一样):
[box_id],[quantity]
答案 0 :(得分:1)
Try this
$ a = $ this->订单 - >查询('SELECT box_id,SUM(数量)AS q FROM order_boxes GROUP BY box_id');