【问题标题】:fatfree framework, bug pr misuse?fatfree 框架,错误公关滥用?
【发布时间】:2017-12-20 17:23:33
【问题描述】:

我在 f3 框架中有这个 db 函数

public function sumOfAmount($startdate, $enddate) {
    $this->amount = 'price*quantity';
    $this->sumamount = 'SUM(price*quantity)';
    $this->load(array('createon > ? AND createon < ?', $startdate, $enddate));

    //return $this->query;
    return $this->cast();
}

似乎 sumamount 不正确,从 f3 日志中我执行了此查询

SELECT `idproduct`,`idtransaction`,`idline`,`name`,`code`,`price`,`quantity`,`createon`,(price * quantity) AS `amount`,(SUM(price * quantity)) AS `sumamount` FROM `qrysales` 

但是如果我在 phpmyadmin 中运行该查询,结果是可以的

有什么想法吗??

【问题讨论】:

  • SELECT column, column, ... SUM(..) ... 在不使用 GROUP BY 的情况下将非聚合列与聚合列混合在一起非常奇怪。当服务器使用 sql_mode = ONLY_FULL_GROUP_BY 时,它甚至是无效的 SQL
  • 你能澄清一下到底是什么问题吗? “似乎 sumamount 不正确”并没有提供太多信息。
  • 确实,您还没有按规则定义任何组.. 将其添加到 $options

标签: php mysql fat-free-framework


【解决方案1】:

我好像忘记了group by子句

public function sumOfAmount($startdate, $enddate) {
    $this->amount = 'price*quantity';
    $this->sumamount = 'SUM(price*quantity)';
    $this->load(array('createon > ? AND createon < ?', $startdate, $enddate,'group' => 'idline'));

    //return $this->query;
    return $this->cast();
}

【讨论】:

  • 3 1/2年解决问题,你超级敬业!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-20
相关资源
最近更新 更多