我有这样的学说查询:
$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,并用不必要的")"替换它。为什么会这样?我正在使用doctrine doctrine 2.3.x-dev和php 5.3。
答案 0 :(得分:2)
尝试在两者之间放置空格)和>在有条款。
$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();
答案 1 :(得分:1)
这应该是诀窍:
->having('SUM(ga.pageViews) > :sum_page_views');
->setParameter('sum_page_views', 100)
希望这会有所帮助: - )