Skip to content

Instantly share code, notes, and snippets.

@jbartek
Created April 21, 2014 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbartek/11141940 to your computer and use it in GitHub Desktop.
Save jbartek/11141940 to your computer and use it in GitHub Desktop.
SugarQuery - Having
<?php
$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$query->join('contacts', array('alias' => 'industryContacts'));
$query->join('opportunities', array('relatedJoin' => 'industryContacts', 'alias' => 'contactsOpportunities'));
$query->select()->setCountQuery();
$query->where()->equals('contactsOpportunities.sales_stage', 'closed');
$havingCondition = new SugarQuery_Builder_Condition($query);
$havingCondition->setField('contactsOpportunities.amount')->setOperator('>')->setValues('1000');
$query->having($havingCondition);
$results = $query->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment