在我的产品数据库中,我有一个价格和数量的列。我想要做的是将每行的价格和数量相乘,然后添加所有值,这样我就能得到我数据库中所有产品的总价格,这是我的代码:
产品型号:
public function getTotalAmountProducts()
{
$this->db->select('sum(price*quantity) as stockvalue', FALSE);
$query = $this->db->get('products');
return $query->result();
}
控制器:
$this->data['totalamount'] = $this->products_model->getTotalAmountProducts();
它不起作用。请帮忙
答案 0 :(得分:0)
应该是
public function getTotalAmountProducts()
{
$this->db->select('price*quantity as stockvalue', FALSE);
$query = $this->db->get('products');
return $query->row()->stockvalue;
}
答案 1 :(得分:0)
试试这个
library(plm)
#sample data
data("Wages", package = "plm")
#plm.data has been deprecated so instead use pdata.frame
Wag <- pdata.frame(Wages, index=595)
plm_model <- plm(lwage ~ black + ed + exp, data = Wag, index = c("id","time"), model="within")
summary(plm_model)