Skip to content

Instantly share code, notes, and snippets.

@jbartek
Created April 18, 2014 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbartek/11063311 to your computer and use it in GitHub Desktop.
Save jbartek/11063311 to your computer and use it in GitHub Desktop.
SugarQuery - GroupBy
<?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');
$query->groupBy('accounts.industry');
$results = $query->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment