+-----+-----+-------+
| PID | Qty | Price |
+-----+-----+-------+
| 1 | 5 | 100 |
| 2 | 10 | 500 |
| 3 | 4 | 300 |
+-----+-----+-------+
$this->db->select("SUM(qty) as total, price as last price");
$this->db->from('table');
$query = $this->db->get();
$result = $query->result();
现在因为有价格,上面的代码将返回尽可能多的行的选择和选择另一列的最后一排,CI如何在另一列查询
我想只返回一行哪里有总数量和价格的最后一个值
预期输出:
Array (
[0] => stdClass Object
(
[total] => 19
[last_price] => 300
)
)
我有成千上万的数量和价格的行的表,但我想选择列数量的总和和上价格的最后价值,而不是数量和价格的所有行的总和,我只想要价格的最后一个价值如何编写我的选择查询?
预先感谢您。
你如何定义最后一行? – Blank
'$ this-> db-> select(“SUM(qty)as total,price as last price ORDER BY PID DESC limit 1”);' –
@AlivetoDie以上不起作用.. –