我有这样的学说查询:

$users = $q->select('ga.publisherId, ga.pageViews')
    ->from('App_Model_GoogleAnalytics ga')
    ->where('ga.dateFrom = ?', array($date))
    ->addWhere("ga.type = 'daily'")->groupBy('ga.publisherId')
    ->having("SUM(ga.pageViews)>100")
    ->fetchArray();


看起来不错。但是执行时,MYSQL代码如下所示:

SELECT o.publisherid AS o__publisherid, o.pageviews AS o__pageviews FROM
googleanalytics_ga o WHERE (o.datefrom = '2014-03-01' AND o.type = 'daily')
GROUP BY o.publisherid HAVING SUM(o.pageviews)>10)


看起来学说“吃”了100个数字中的最后0个,并用不必要的“)”代替。为什么会这样呢?我正在使用教义教义2.3.x-dev和php 5.3。

最佳答案

尝试在Have子句中的)和>之间放置空格。

$users = $q->select('ga.publisherId, ga.pageViews') ->from('App_Model_GoogleAnalytics ga') ->where('ga.dateFrom = ?', array($date)) ->addWhere("ga.type = 'daily'")->groupBy('ga.publisherId') ->having("SUM(ga.pageViews) > 100") ->fetchArray();

关于php - 原则用括号替换最后一个查询字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22683073/

10-16 13:43