gpt4 book ai didi

mysql - 单列的代码点火器总和查询

转载 作者:行者123 更新时间:2023-11-30 22:56:37 27 4
gpt4 key购买 nike

有一个查询,我试图返回值超过 10,000 的列的总和结果。我试过将 sum(value) 作为总计添加到查询中,但它不起作用。

我的代码是:

    $this->db->select('sum(value) as total, date, member_id');
$this->db->where('member_id', $_SESSION['sess_user_id']);
$this->db->where('cost.value >', '9999');
$this->db->where('cost.date = DATE_SUB(NOW(), INTERVAL 5 DAY)');

$query = $this->db->get('orders');

return $query->num_rows();

这是原始 SQL 输出:

SELECT sum(value) as total,datemember_id FROM (steps) WHERE member_id = ' 1' AND cost.value > '9999' AND cost.date = DATE_SUB(NOW(), INTERVAL 5 天)

最佳答案

function cart_product_join()
{
$this->db->select('products.product_id,cart.product_id,SUM(products.special_price*cart.product_qty)');
$this->db->from('products');
$this->db->join('cart', 'cart.product_id = products.product_id', 'right');
$result = $this->db->get()->result();
return $result;
//$result=$this->db->last_query();
//echo $result;
}

关于mysql - 单列的代码点火器总和查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26103159/

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